From 4984925dd833de89db9464d771f3013ba35f1b2d Mon Sep 17 00:00:00 2001 From: falendikategar Date: Thu, 7 Nov 2024 11:57:14 +0700 Subject: [PATCH] uodate: return to the previous concept of getAnswers endpoint in assessments because formatted resulted will be handled in the frontend --- apps/backend/src/routes/assessments/route.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/backend/src/routes/assessments/route.ts b/apps/backend/src/routes/assessments/route.ts index a319cb5..a720084 100644 --- a/apps/backend/src/routes/assessments/route.ts +++ b/apps/backend/src/routes/assessments/route.ts @@ -381,13 +381,13 @@ const assessmentsRoute = new Hono() ), async (c) => { const { assessmentId, page, limit, q } = c.req.valid("query"); - + // Query to count total answers for the specific assessmentId const totalCountQuery = sql`(SELECT count(*) FROM ${answers} WHERE ${answers.assessmentId} = ${assessmentId})`; - + // Query to retrieve answers for the specific assessmentId const result = await db .select({ @@ -416,17 +416,9 @@ const assessmentsRoute = new Hono() ) .offset(page * limit) .limit(limit); - - // Format the result to return an object where questionId is the key and optionId is the value - const formattedResult = result.reduce((acc, item) => { - if (item.questionId != null && item.optionId != null) { - acc[item.questionId] = item.optionId; - } - return acc; - }, {} as Record); // Type assertion to ensure the accumulator is an object with string keys and values - + return c.json({ - data: formattedResult, + data: result.map((d) => ({ ...d, fullCount: undefined })), _metadata: { currentPage: page, totalPages: Math.ceil( @@ -437,7 +429,7 @@ const assessmentsRoute = new Hono() }, }); } - ) + ) .get( "/getAllAnswers/:assessmentId", // Use :assessmentId in the URL path