Skip to content

Commit

Permalink
max 2 reviews per cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrwang committed Jan 22, 2025
1 parent 9fa28f5 commit 06360d6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/api/src/router/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const reviewRouter = {
create: protectedProcedure
.input(CreateReviewSchema)
.mutation(async ({ ctx, input }) => {
console.log("hey");
console.log("new review");
if (!input.profileId) {
console.log("no profile id");
throw new TRPCError({
Expand All @@ -92,6 +92,18 @@ export const reviewRouter = {
message: "You can only leave 5 reviews",
});
}
const reviewsInSameCycle = reviews.filter(
(review) =>
review.workTerm === input.workTerm &&
review.workYear === input.workYear,
);
if (reviewsInSameCycle.length >= 2) {
console.log("already 2 in same cycle");
throw new TRPCError({
code: "FORBIDDEN",
message: "You can only leave 2 reviews per cycle",
});
}
console.log("success");
return ctx.db.insert(Review).values(input);
}),
Expand Down

0 comments on commit 06360d6

Please sign in to comment.