From 03642363e5029789353413923bf278f8732988c3 Mon Sep 17 00:00:00 2001 From: JurreBrandsenInfoSupport <149962077+JurreBrandsenInfoSupport@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:46:26 +0100 Subject: [PATCH] Only selected roles are now shown in the result PDF (#37) --- src/app/thank-you/page.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/app/thank-you/page.tsx b/src/app/thank-you/page.tsx index ff53cbe..6eed521 100644 --- a/src/app/thank-you/page.tsx +++ b/src/app/thank-you/page.tsx @@ -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(