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",
|
"query",
|
||||||
z.object({
|
z.object({
|
||||||
assessmentId: z.string(), // Require assessmentId as a query parameter
|
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) => {
|
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
|
// Query to count total answers for the specific assessmentId
|
||||||
const totalCountQuery =
|
const totalCountQuery =
|
||||||
|
|
@ -405,28 +398,11 @@ const assessmentsRoute = new Hono<HonoEnv>()
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(answers.assessmentId, assessmentId), // Filter by assessmentId
|
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({
|
return c.json({
|
||||||
data: result.map((d) => ({ ...d, fullCount: undefined })),
|
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