diff --git a/server/src/routes/api/admin/test-checklist.js b/server/src/routes/api/admin/test-checklist.js index 17c2cff..cfd5e00 100644 --- a/server/src/routes/api/admin/test-checklist.js +++ b/server/src/routes/api/admin/test-checklist.js @@ -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) => {