update: removal of metadata and pagination on the getAnswers endpoint in assessments
This commit is contained in:
parent
4984925dd8
commit
bb106289cf
|
|
@ -370,17 +370,10 @@ const assessmentsRoute = new Hono<HonoEnv>()
|
|||
"query",
|
||||
z.object({
|
||||
assessmentId: z.string(), // Require assessmentId as a query parameter
|
||||
withMetadata: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((v) => v?.toLowerCase() === "true"),
|
||||
page: z.coerce.number().int().min(0).default(0),
|
||||
limit: z.coerce.number().int().min(1).max(1000).default(1000),
|
||||
q: z.string().default(""),
|
||||
})
|
||||
),
|
||||
async (c) => {
|
||||
const { assessmentId, page, limit, q } = c.req.valid("query");
|
||||
const { assessmentId } = c.req.valid("query");
|
||||
|
||||
// Query to count total answers for the specific assessmentId
|
||||
const totalCountQuery =
|
||||
|
|
@ -405,28 +398,11 @@ const assessmentsRoute = new Hono<HonoEnv>()
|
|||
.where(
|
||||
and(
|
||||
eq(answers.assessmentId, assessmentId), // Filter by assessmentId
|
||||
q
|
||||
? or(
|
||||
ilike(answers.filename, q),
|
||||
ilike(answers.validationInformation, q),
|
||||
eq(answers.id, q)
|
||||
)
|
||||
: undefined
|
||||
)
|
||||
)
|
||||
.offset(page * limit)
|
||||
.limit(limit);
|
||||
|
||||
return c.json({
|
||||
data: result.map((d) => ({ ...d, fullCount: undefined })),
|
||||
_metadata: {
|
||||
currentPage: page,
|
||||
totalPages: Math.ceil(
|
||||
(Number(result[0]?.fullCount) ?? 0) / limit
|
||||
),
|
||||
totalItems: Number(result[0]?.fullCount) ?? 0,
|
||||
perPage: limit,
|
||||
},
|
||||
});
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user