Skip to content

Commit

Permalink
Only selected roles are now shown in the result PDF (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
JurreBrandsenInfoSupport authored Mar 22, 2024
1 parent 3dc0ae6 commit 0364236
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/thank-you/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ const ThankYou = async () => {

const answerOptions: AnswerOption[] = await db.answerOption.findMany();

const userSelectedRoles = await db.user.findUnique({
where: {
id: session?.user.id,
},
include: {
roles: true,
},
});

// Update the userAnswersForRole object such that a question only includes the roles of the selected roles of the user.
for (const userAnswer of userAnswersForRole) {
userAnswer.question.roles = userAnswer.question.roles?.filter((role) =>
userSelectedRoles?.roles.some(
(selectedRole) => selectedRole.id === role.id,
),
);
}

const transformedData = userAnswersForRole.reduce(
(acc, curr) => {
const existingQuestion = acc.find(
Expand Down

0 comments on commit 0364236

Please sign in to comment.