feat: support comment field in test-checklist API

This commit is contained in:
Kirill
2026-05-24 16:52:38 +05:00
parent 5ef3861e84
commit 42c83b5d4e
+11 -5
View File
@@ -5,24 +5,30 @@ export async function registerAdminTestChecklistRoutes(fastify) {
const results = await prisma.checklistResult.findMany()
const resultMap = {}
for (const r of results) {
resultMap[r.itemKey] = { passed: r.passed, checkedAt: r.checkedAt.toISOString() }
resultMap[r.itemKey] = { passed: r.passed, comment: r.comment, checkedAt: r.checkedAt.toISOString() }
}
return { results: resultMap }
})
fastify.patch('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
const { itemKey, passed } = request.body || {}
const { itemKey, passed, comment } = request.body || {}
if (!itemKey || typeof passed !== 'boolean') {
return reply.code(400).send({ error: 'itemKey и passed (boolean) обязательны' })
}
if (comment !== undefined && typeof comment !== 'string') {
return reply.code(400).send({ error: 'comment должен быть строкой' })
}
if (comment !== undefined && comment.length > 2000) {
return reply.code(400).send({ error: 'Комментарий слишком длинный (макс. 2000 символов)' })
}
const result = await prisma.checklistResult.upsert({
where: { itemKey },
create: { itemKey, passed },
update: { passed, checkedAt: new Date() },
create: { itemKey, passed, comment: passed ? null : comment || null },
update: { passed, comment: passed ? null : comment ?? undefined, checkedAt: new Date() },
})
return { result: { itemKey: result.itemKey, passed: result.passed, checkedAt: result.checkedAt.toISOString() } }
return { result: { itemKey: result.itemKey, passed: result.passed, comment: result.comment, checkedAt: result.checkedAt.toISOString() } }
})
fastify.post('/api/admin/test-checklist/reset', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {