fix: align test-checklist error handling with project convention

This commit is contained in:
Kirill
2026-05-24 16:21:33 +05:00
parent dc1c004a82
commit 83ae974017
@@ -1,7 +1,7 @@
import { prisma } from '../../../lib/prisma.js'
export async function registerAdminTestChecklistRoutes(fastify) {
fastify.get('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async () => {
fastify.get('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
const results = await prisma.checklistResult.findMany()
const resultMap = {}
for (const r of results) {
@@ -10,10 +10,10 @@ export async function registerAdminTestChecklistRoutes(fastify) {
return { results: resultMap }
})
fastify.patch('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async (request) => {
fastify.patch('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
const { itemKey, passed } = request.body || {}
if (!itemKey || typeof passed !== 'boolean') {
return fastify.httpErrors.badRequest('itemKey and passed (boolean) are required')
return reply.code(400).send({ error: 'itemKey и passed (boolean) обязательны' })
}
const result = await prisma.checklistResult.upsert({
@@ -25,7 +25,7 @@ export async function registerAdminTestChecklistRoutes(fastify) {
return { result: { itemKey: result.itemKey, passed: result.passed, checkedAt: result.checkedAt.toISOString() } }
})
fastify.post('/api/admin/test-checklist/reset', { preHandler: [fastify.verifyAdmin] }, async () => {
fastify.post('/api/admin/test-checklist/reset', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
await prisma.checklistResult.deleteMany({})
return { ok: true }
})