Pull Request branch dev-clone to main #1
|
|
@ -381,13 +381,13 @@ const assessmentsRoute = new Hono<HonoEnv>()
|
||||||
),
|
),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { assessmentId, page, limit, q } = c.req.valid("query");
|
const { assessmentId, page, limit, q } = c.req.valid("query");
|
||||||
|
|
||||||
// Query to count total answers for the specific assessmentId
|
// Query to count total answers for the specific assessmentId
|
||||||
const totalCountQuery =
|
const totalCountQuery =
|
||||||
sql<number>`(SELECT count(*)
|
sql<number>`(SELECT count(*)
|
||||||
FROM ${answers}
|
FROM ${answers}
|
||||||
WHERE ${answers.assessmentId} = ${assessmentId})`;
|
WHERE ${answers.assessmentId} = ${assessmentId})`;
|
||||||
|
|
||||||
// Query to retrieve answers for the specific assessmentId
|
// Query to retrieve answers for the specific assessmentId
|
||||||
const result = await db
|
const result = await db
|
||||||
.select({
|
.select({
|
||||||
|
|
@ -416,17 +416,9 @@ const assessmentsRoute = new Hono<HonoEnv>()
|
||||||
)
|
)
|
||||||
.offset(page * limit)
|
.offset(page * limit)
|
||||||
.limit(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<string, string>); // Type assertion to ensure the accumulator is an object with string keys and values
|
|
||||||
|
|
||||||
return c.json({
|
return c.json({
|
||||||
data: formattedResult,
|
data: result.map((d) => ({ ...d, fullCount: undefined })),
|
||||||
_metadata: {
|
_metadata: {
|
||||||
currentPage: page,
|
currentPage: page,
|
||||||
totalPages: Math.ceil(
|
totalPages: Math.ceil(
|
||||||
|
|
@ -437,7 +429,7 @@ const assessmentsRoute = new Hono<HonoEnv>()
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
.get(
|
.get(
|
||||||
"/getAllAnswers/:assessmentId", // Use :assessmentId in the URL path
|
"/getAllAnswers/:assessmentId", // Use :assessmentId in the URL path
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user