diff --git a/api/src/controllers/reviewController.ts b/api/src/controllers/reviewController.ts index 6104e23..8f8ec4b 100644 --- a/api/src/controllers/reviewController.ts +++ b/api/src/controllers/reviewController.ts @@ -18,6 +18,7 @@ new Docs( export async function add_post(req: Request, res: Response) { try { const data: IReview = req.body; + data.user_id = res.locals.user._id const review = new Review(data); await review.save(); res.status(201).json(Log.info(201, "review was added", review)); diff --git a/api/src/models/Review.ts b/api/src/models/Review.ts index f9a4fcf..7c39149 100644 --- a/api/src/models/Review.ts +++ b/api/src/models/Review.ts @@ -28,6 +28,14 @@ const schema = new Schema( type: Boolean, required: true, }, + beer_id: { + type: String, + required: true, + }, + user_id: { + type: String, + required: true, + } }, { timestamps: true, diff --git a/api/src/validators/reviewValidator.ts b/api/src/validators/reviewValidator.ts index ae1799d..03fe14c 100644 --- a/api/src/validators/reviewValidator.ts +++ b/api/src/validators/reviewValidator.ts @@ -20,6 +20,7 @@ export const add = yup.object({ packaging: yup.number().min(1).max(5).required(), sourness: yup.boolean().required(), would_again: yup.boolean().required(), + user_id: yup.string().notRequired() }); export interface IReview extends yup.InferType, mongooseAddition {} export const addExam: IReview = { diff --git a/frontend/.gitignore b/frontend/.gitignore index 50f5130..778538e 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -37,3 +37,4 @@ yarn-error.* .env .vscode/ +*.swp diff --git a/frontend/app/(app)/(tabs)/_layout.js b/frontend/app/(app)/(tabs)/_layout.js index 8b8d7d7..57ff21b 100644 --- a/frontend/app/(app)/(tabs)/_layout.js +++ b/frontend/app/(app)/(tabs)/_layout.js @@ -67,7 +67,7 @@ export default function TabLayout() { options={{ href: null, title: "Add beer" }} /> diff --git a/frontend/app/(app)/(tabs)/beer/index.js b/frontend/app/(app)/(tabs)/beer/index.js index 2977b1f..5349bcf 100644 --- a/frontend/app/(app)/(tabs)/beer/index.js +++ b/frontend/app/(app)/(tabs)/beer/index.js @@ -87,7 +87,7 @@ export default function Tab() { title="Add review" color={colors.gold} onPress={() => { - router.push(`/review/${item._id}`); + router.push(`/review/add/${item._id}`); }} /> diff --git a/frontend/app/(app)/(tabs)/review/.index.js.swp b/frontend/app/(app)/(tabs)/review/.index.js.swp deleted file mode 100644 index b42827b..0000000 Binary files a/frontend/app/(app)/(tabs)/review/.index.js.swp and /dev/null differ diff --git a/frontend/app/(app)/(tabs)/review/add.js b/frontend/app/(app)/(tabs)/review/add/[beer_id].js similarity index 97% rename from frontend/app/(app)/(tabs)/review/add.js rename to frontend/app/(app)/(tabs)/review/add/[beer_id].js index 8ffde5c..dd6cef9 100644 --- a/frontend/app/(app)/(tabs)/review/add.js +++ b/frontend/app/(app)/(tabs)/review/add/[beer_id].js @@ -7,9 +7,11 @@ import * as ImagePicker from "expo-image-picker"; import DropDownPicker from "react-native-dropdown-picker"; const DropdownTheme = require("@components/DropdownTheme"); import { Platform } from "react-native"; +import { useLocalSearchParams } from "expo-router"; export default function reviewAdd() { // States for each dropdown + const routeParams = useLocalSearchParams(); const [openFoam, setOpenFoam] = useState(false); const [openBitterSweetness, setOpenBitterSweetness] = useState(false); const [openTaste, setOpenTaste] = useState(false); @@ -311,6 +313,7 @@ export default function reviewAdd() { credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ + beer_id: routeParams.beer_id, foam: itemFoam, bitter_sweetness: itemBitter_sweetness, taste: itemTaste, @@ -322,10 +325,12 @@ export default function reviewAdd() { const res = await req.json(); if (res.code == 201 && res.data._id) { - window.location.href = `/review/${res.data._id}`; + // window.location.href = `/review/${res.data._id}`; + // TODO: use react router for redirect + alert("Review was added!"); } else { alert( - "Beer was not added successfully. Please check your data and try again.", + "Review was not added successfully. Please check your data and try again.", ); } }