diff --git a/api/src/controllers/reviews.ts b/api/src/controllers/reviews.ts index 61b16217..dcae676a 100644 --- a/api/src/controllers/reviews.ts +++ b/api/src/controllers/reviews.ts @@ -123,10 +123,14 @@ const reviewsRouter = router({ ...input, userId: userId, verified: verifiedCount >= 3, // auto-verify if use has 3+ verified reviews + updatedAt: input.updatedAt ? new Date(input.updatedAt) : undefined, }; // Verify the captcha - const verifyResponse = await verifyCaptcha(reviewToAdd); + const verifyResponse = await verifyCaptcha({ + ...reviewToAdd, + updatedAt: reviewToAdd.updatedAt?.toISOString(), + }); if (!verifyResponse?.success) throw new TRPCError({ code: 'BAD_REQUEST', message: 'ReCAPTCHA token is invalid' }); const addedReview = (await db.insert(review).values(reviewToAdd).returning())[0]; @@ -179,7 +183,13 @@ const reviewsRouter = router({ } const { id, ...updateWithoutId } = input; - await db.update(review).set(updateWithoutId).where(eq(review.id, id)); + await db + .update(review) + .set({ + ...updateWithoutId, + updatedAt: new Date(), + }) + .where(eq(review.id, id)); return true; }), diff --git a/site/src/component/Review/SubReview.tsx b/site/src/component/Review/SubReview.tsx index 2e4bf62d..30e9560e 100644 --- a/site/src/component/Review/SubReview.tsx +++ b/site/src/component/Review/SubReview.tsx @@ -197,6 +197,20 @@ const SubReview: FC = ({ review, course, professor }) => { })}

+ {review.updatedAt && ( +

+ <> + Updated:{' '} + + {new Date(review.updatedAt).toLocaleString('default', { + year: 'numeric', + month: 'long', + day: 'numeric', + })} + + +

+ )}

Quarter: {review.quarter}

diff --git a/site/src/component/ReviewForm/ReviewForm.tsx b/site/src/component/ReviewForm/ReviewForm.tsx index dd7ea156..35a255d5 100644 --- a/site/src/component/ReviewForm/ReviewForm.tsx +++ b/site/src/component/ReviewForm/ReviewForm.tsx @@ -135,6 +135,7 @@ const ReviewForm: FC = ({ textbook, attendance, tags: selectedTags, + updatedAt: editing ? new Date().toISOString() : undefined, captchaToken, }; diff --git a/types/src/review.ts b/types/src/review.ts index 41541e4c..7e595c72 100644 --- a/types/src/review.ts +++ b/types/src/review.ts @@ -41,6 +41,7 @@ export const reviewSubmission = z.object({ textbook: z.boolean(), attendance: z.boolean(), tags: z.array(tagsEnum), + updatedAt: z.string().optional(), captchaToken: z.string().optional(), }); export type ReviewSubmission = z.infer;