fix: align test-checklist error handling with project convention
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { prisma } from '../../../lib/prisma.js'
|
import { prisma } from '../../../lib/prisma.js'
|
||||||
|
|
||||||
export async function registerAdminTestChecklistRoutes(fastify) {
|
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 results = await prisma.checklistResult.findMany()
|
||||||
const resultMap = {}
|
const resultMap = {}
|
||||||
for (const r of results) {
|
for (const r of results) {
|
||||||
@@ -10,10 +10,10 @@ export async function registerAdminTestChecklistRoutes(fastify) {
|
|||||||
return { results: resultMap }
|
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 || {}
|
const { itemKey, passed } = request.body || {}
|
||||||
if (!itemKey || typeof passed !== 'boolean') {
|
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({
|
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() } }
|
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({})
|
await prisma.checklistResult.deleteMany({})
|
||||||
return { ok: true }
|
return { ok: true }
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user