fix(plugin-nested-docs): sync write transaction errors (#4084)
This commit is contained in:
@@ -8,17 +8,10 @@ import { seed } from './seed'
|
||||
export default buildConfigWithDefaults({
|
||||
collections: [Pages, Users],
|
||||
localization: {
|
||||
locales: ['en', 'es', 'de'],
|
||||
defaultLocale: 'en',
|
||||
fallback: true,
|
||||
locales: ['en', 'es', 'de'],
|
||||
},
|
||||
plugins: [
|
||||
nestedDocs({
|
||||
collections: ['pages'],
|
||||
generateLabel: (_, doc) => doc.title as string,
|
||||
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.slug}`, ''),
|
||||
}),
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
@@ -30,4 +23,11 @@ export default buildConfigWithDefaults({
|
||||
|
||||
await seed(payload)
|
||||
},
|
||||
plugins: [
|
||||
nestedDocs({
|
||||
collections: ['pages'],
|
||||
generateLabel: (_, doc) => doc.title as string,
|
||||
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.slug}`, ''),
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { Payload } from '../../../packages/payload/src'
|
||||
import type { PayloadRequest } from '../../../packages/payload/src/express/types'
|
||||
|
||||
export const seed = async (payload: Payload): Promise<boolean> => {
|
||||
payload.logger.info('Seeding data...')
|
||||
const req = {} as PayloadRequest
|
||||
|
||||
try {
|
||||
await payload.create({
|
||||
@@ -10,40 +12,45 @@ export const seed = async (payload: Payload): Promise<boolean> => {
|
||||
email: 'demo@payloadcms.com',
|
||||
password: 'demo',
|
||||
},
|
||||
req,
|
||||
})
|
||||
|
||||
const { id: parentID } = await payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
title: 'Parent page',
|
||||
slug: 'parent-page',
|
||||
title: 'Parent page',
|
||||
},
|
||||
req,
|
||||
})
|
||||
|
||||
const { id: childID } = await payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
title: 'Child page',
|
||||
slug: 'child-page',
|
||||
parent: parentID,
|
||||
slug: 'child-page',
|
||||
title: 'Child page',
|
||||
},
|
||||
req,
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
title: 'Grandchild page',
|
||||
slug: 'grandchild-page',
|
||||
parent: childID,
|
||||
slug: 'grandchild-page',
|
||||
title: 'Grandchild page',
|
||||
},
|
||||
req,
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: 'pages',
|
||||
data: {
|
||||
title: 'Sister page',
|
||||
slug: 'sister-page',
|
||||
title: 'Sister page',
|
||||
},
|
||||
req,
|
||||
})
|
||||
return true
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user