diff --git a/server/src/routes/api.js b/server/src/routes/api.js index 0c20dd4..4cdcfbc 100644 --- a/server/src/routes/api.js +++ b/server/src/routes/api.js @@ -1,5 +1,6 @@ import { mapProductForApi, parseMaterialsInput, slugify } from './api/_product-helpers.js' import { registerAdminNotificationRoutes } from './api/admin/notifications.js' +import { registerAdminTestChecklistRoutes } from './api/admin/test-checklist.js' import { registerAdminCategoryRoutes } from './api/admin-categories.js' import { registerAdminGalleryRoutes } from './api/admin-gallery.js' import { registerAdminOrderRoutes } from './api/admin-orders.js' @@ -31,6 +32,7 @@ export async function registerApiRoutes(fastify) { await registerAdminReviewRoutes(fastify) await registerAdminUserRoutes(fastify) await registerAdminNotificationRoutes(fastify) + await registerAdminTestChecklistRoutes(fastify) await registerAdminProfileRoutes(fastify) await registerAuthRoutes(fastify) diff --git a/server/src/routes/api/admin/test-checklist.js b/server/src/routes/api/admin/test-checklist.js new file mode 100644 index 0000000..6d0e265 --- /dev/null +++ b/server/src/routes/api/admin/test-checklist.js @@ -0,0 +1,32 @@ +import { prisma } from '../../../lib/prisma.js' + +export async function registerAdminTestChecklistRoutes(fastify) { + fastify.get('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async () => { + const results = await prisma.checklistResult.findMany() + const resultMap = {} + for (const r of results) { + resultMap[r.itemKey] = { passed: r.passed, checkedAt: r.checkedAt.toISOString() } + } + return { results: resultMap } + }) + + fastify.patch('/api/admin/test-checklist', { preHandler: [fastify.verifyAdmin] }, async (request) => { + const { itemKey, passed } = request.body || {} + if (!itemKey || typeof passed !== 'boolean') { + return fastify.httpErrors.badRequest('itemKey and passed (boolean) are required') + } + + const result = await prisma.checklistResult.upsert({ + where: { itemKey }, + create: { itemKey, passed }, + update: { passed, checkedAt: new Date() }, + }) + + return { result: { itemKey: result.itemKey, passed: result.passed, checkedAt: result.checkedAt.toISOString() } } + }) + + fastify.post('/api/admin/test-checklist/reset', { preHandler: [fastify.verifyAdmin] }, async () => { + await prisma.checklistResult.deleteMany({}) + return { ok: true } + }) +}