feat: support comment field in test-checklist API
This commit is contained in:
@@ -5,24 +5,30 @@ export async function registerAdminTestChecklistRoutes(fastify) {
|
|||||||
const results = await prisma.checklistResult.findMany()
|
const results = await prisma.checklistResult.findMany()
|
||||||
const resultMap = {}
|
const resultMap = {}
|
||||||
for (const r of results) {
|
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 }
|
return { results: resultMap }
|
||||||
})
|
})
|
||||||
|
|
||||||
fastify.patch('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
|
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') {
|
if (!itemKey || typeof passed !== 'boolean') {
|
||||||
return reply.code(400).send({ error: 'itemKey и 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({
|
const result = await prisma.checklistResult.upsert({
|
||||||
where: { itemKey },
|
where: { itemKey },
|
||||||
create: { itemKey, passed },
|
create: { itemKey, passed, comment: passed ? null : comment || null },
|
||||||
update: { passed, checkedAt: new Date() },
|
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) => {
|
fastify.post('/api/admin/test-checklist/reset', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user