From 986aca393183b979e3c15f6c4a1c28adbed145e4 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Wed, 15 May 2024 01:35:52 +0200 Subject: [PATCH] Fixed: review add - send add request to api --- api/src/controllers/reviewController.ts | 1 + api/src/models/Review.ts | 8 ++++++++ api/src/validators/reviewValidator.ts | 1 + frontend/.gitignore | 1 + frontend/app/(app)/(tabs)/_layout.js | 2 +- frontend/app/(app)/(tabs)/beer/index.js | 2 +- frontend/app/(app)/(tabs)/review/.index.js.swp | Bin 12288 -> 0 bytes .../(tabs)/review/{add.js => add/[beer_id].js} | 9 +++++++-- 8 files changed, 20 insertions(+), 4 deletions(-) delete mode 100644 frontend/app/(app)/(tabs)/review/.index.js.swp rename frontend/app/(app)/(tabs)/review/{add.js => add/[beer_id].js} (97%) 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 b42827bc3c5bef7845e09d43459d4c122cf50626..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&x;&I6vrz$h;3XIh2X(J*(TTnvpu_pfM#bFvzs-p>?Y&>h(cI4wcRzdz1!0@ zsjk_Xu^BxmUh+4H9*sBAix&wJA_yJ?#gl)7*C3*PtGee$)-eEz$#!BunJfOtO8a6tAJI&Dqt0`3RndmLIqez$k&e& z@|%O;@&Etf-~V@>B;;do0Nwznz;odDCkXiod;`7!pMhK8CU_s511@+3{5eI)FW@ft z5_|+Q&;<&lAOe>_6`TQ6;NIhe{0P1W--5f~D{u?k1Y4j6PJw$T2>Ahg3i==h9BhM4 z@FutdE`!tHBsc+neT^KS#TWu0j;!NMze=-&27k5 z0jq#jz$#!BunPQN6&RG}h%+b?$7wOyjFJVRlxUr&?zuCr?rpO$jFRSgI(t?(cZ3YN zTw`I>Nzpem?t3c=)h@cmJ&Ph15}ulp^|h}^aX8NIn{Gq2|2E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