Skip to content

Commit

Permalink
Add Updated At Date to the Review Card (#534)
Browse files Browse the repository at this point in the history
* Update SubReview.tsx
* Set updatedAt & display under createdAt
* Set & display updatedAt under createdAt on the client
* update reviews.ts and SubReview.tsx
* Update SubReview.tsx
* update ReviewForm.tsx

---------

Co-authored-by: Awesome-E <[email protected]>
  • Loading branch information
philosolog and Awesome-E authored Jan 29, 2025
1 parent 57d126e commit 6696237
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions api/src/controllers/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}),

Expand Down
14 changes: 14 additions & 0 deletions site/src/component/Review/SubReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ const SubReview: FC<SubReviewProps> = ({ review, course, professor }) => {
})}
</b>
</p>
{review.updatedAt && (
<p>
<>
Updated:{' '}
<b>
{new Date(review.updatedAt).toLocaleString('default', {
year: 'numeric',
month: 'long',
day: 'numeric',
})}
</b>
</>
</p>
)}
<p>
Quarter: <b>{review.quarter}</b>
</p>
Expand Down
1 change: 1 addition & 0 deletions site/src/component/ReviewForm/ReviewForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const ReviewForm: FC<ReviewFormProps> = ({
textbook,
attendance,
tags: selectedTags,
updatedAt: editing ? new Date().toISOString() : undefined,
captchaToken,
};

Expand Down
1 change: 1 addition & 0 deletions types/src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof reviewSubmission>;
Expand Down

0 comments on commit 6696237

Please sign in to comment.