From 94889f4e7d72d919fda57c1ea03657f8eafdb7ff Mon Sep 17 00:00:00 2001 From: "Grayson, Matthew" Date: Sun, 14 Apr 2024 14:35:08 -0500 Subject: [PATCH] Add resources to assessments/{id}; add sorting by category.number and question.number. --- backend/src/api/assessments.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/src/api/assessments.ts b/backend/src/api/assessments.ts index 56e1f582..6ce4a6da 100644 --- a/backend/src/api/assessments.ts +++ b/backend/src/api/assessments.ts @@ -79,7 +79,8 @@ export const get = wrapHandler(async (event) => { relations: [ 'responses', 'responses.question', - 'responses.question.category' + 'responses.question.category', + 'responses.question.resources' ] }); @@ -87,6 +88,20 @@ export const get = wrapHandler(async (event) => { return NotFound; } + // Sort responses by question.number and then by category.number + assessment.responses.sort((a, b) => { + const questionNumberComparison = a.question.number.localeCompare( + b.question.number + ); + if (questionNumberComparison !== 0) { + return questionNumberComparison; + } else { + return a.question.category.number.localeCompare( + b.question.category.number + ); + } + }); + const responsesByCategory = assessment.responses.reduce((acc, response) => { const categoryName = response.question.category.name; if (!acc[categoryName]) {