feat: add admin test-checklist API routes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 }
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user