Skip to content

Commit

Permalink
admin can see but not edit all reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyro292 committed Jul 27, 2024
1 parent 049de1a commit 90f2364
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ export default async function Review({ params }: ReviewProps) {
where: {
id: Number(params.review_id),
},
include: { application: true, questionnaire: true },
include: { application: true, questionnaire: true, user: true },
});

if (!review) redirect("/404");
if (review.userId !== session.user.id) redirect("/404");

const opportunityTitle = db.opportunity.findUnique({
where: {
id: review?.application.opportunityId,
},
}).then((opportunity) => opportunity?.title);

if (!review) redirect("/404");

const questions = review.questionnaire.questions as Question[];

Expand Down
45 changes: 33 additions & 12 deletions app/opportunities/[opportunity_id]/review/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,44 @@ export default async function ReviewPage({ params }: ReviewPageProps) {
include: { admins: true },
});

const reviews = await db.review.findMany({
where: {
application: { opportunityId: Number(params.opportunity_id) },
userId: session.user.id,
},
include: {
application: true,
user: { select: { name: true } },
questionnaire: { include: { phase: true } },
},
});
if (!opportunity) redirect("/404");

let reviews;

if (opportunity.admins.some((admin) => admin.id === session.user.id)) {

reviews = await db.review.findMany({
where: {
application: { opportunityId: Number(params.opportunity_id) },
},
include: {
application: true,
user: { select: { name: true } },
questionnaire: { include: { phase: true } },
},
});
} else {
reviews = await db.review.findMany({
where: {
application: { opportunityId: Number(params.opportunity_id) },
userId: session.user.id,
},
include: {
application: true,
user: { select: { name: true } },
questionnaire: { include: { phase: true } },
},
});
}

return (
<div className="space-y-8 p-8">
<div className="flex justify-between">
<div>
<Breadcrumbs title={"Reviews"} opportunityTitle={opportunity?.title} />
<Breadcrumbs
title={"Reviews"}
opportunityTitle={opportunity?.title}
/>
<h1 className="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl">
Reviews
</h1>
Expand Down

0 comments on commit 90f2364

Please sign in to comment.