MCPcopy
hub / github.com/payloadcms/payload / seedHandler

Function seedHandler

examples/localization/src/endpoints/seedHandler.ts:5–27  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

3import { seed as seedScript } from '@/endpoints/seed'
4
5export 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}

Callers

nothing calls this directly

Calls 4

initTransactionFunction · 0.90
commitTransactionFunction · 0.90
jsonMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…