(req)
| 3 | import { seed as seedScript } from '@/endpoints/seed' |
| 4 | |
| 5 | export const seedHandler: PayloadHandler = async (req): Promise<Response> => { |
| 6 | const { payload, user } = req |
| 7 | |
| 8 | if (!user) { |
| 9 | return Response.json({ error: 'Unauthorized' }, { status: 401 }) |
| 10 | } |
| 11 | |
| 12 | try { |
| 13 | // Create a transaction so that all seeding happens in one transaction |
| 14 | await initTransaction(req) |
| 15 | |
| 16 | await seedScript({ payload, req }) |
| 17 | |
| 18 | // Finalise transactiojn |
| 19 | await commitTransaction(req) |
| 20 | |
| 21 | return Response.json({ success: true }) |
| 22 | } catch (error: unknown) { |
| 23 | const message = error instanceof Error ? error.message : 'Unknown error' |
| 24 | payload.logger.error({ err: error, message: 'Error seeding data' }) |
| 25 | return Response.json({ error: message }, { status: 500 }) |
| 26 | } |
| 27 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…