Skip to content

Commit

Permalink
Add resources to assessments/{id}; add sorting by category.number and…
Browse files Browse the repository at this point in the history
… question.number.
  • Loading branch information
Matthew-Grayson committed Apr 14, 2024
1 parent f18b228 commit 94889f4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion backend/src/api/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,29 @@ export const get = wrapHandler(async (event) => {
relations: [
'responses',
'responses.question',
'responses.question.category'
'responses.question.category',
'responses.question.resources'
]
});

if (!assessment) {
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]) {
Expand Down

0 comments on commit 94889f4

Please sign in to comment.