fix(templates): remove req from seed script

This commit is contained in:
Elliot DeNolf
2024-11-18 16:58:16 -05:00
parent 7314990b0c
commit ecbafbf181
2 changed files with 2 additions and 100 deletions

View File

@@ -48,7 +48,6 @@ export const seed = async ({
data: { data: {
navItems: [], navItems: [],
}, },
req,
}) })
} }
@@ -60,18 +59,14 @@ export const seed = async ({
exists: true, exists: true,
}, },
}, },
req,
}) })
} }
const pages = await payload.delete({ const pages = await payload.delete({
collection: 'pages', collection: 'pages',
where: {}, where: {},
req,
}) })
console.log({ pages })
payload.logger.info(`— Seeding demo author and user...`) payload.logger.info(`— Seeding demo author and user...`)
await payload.delete({ await payload.delete({
@@ -81,7 +76,6 @@ export const seed = async ({
equals: 'demo-author@payloadcms.com', equals: 'demo-author@payloadcms.com',
}, },
}, },
req,
}) })
const demoAuthor = await payload.create({ const demoAuthor = await payload.create({
@@ -91,7 +85,6 @@ export const seed = async ({
email: 'demo-author@payloadcms.com', email: 'demo-author@payloadcms.com',
password: 'password', password: 'password',
}, },
req,
}) })
let demoAuthorID: number | string = demoAuthor.id let demoAuthorID: number | string = demoAuthor.id
@@ -111,34 +104,11 @@ export const seed = async ({
'https://raw.githubusercontent.com/payloadcms/payload/refs/heads/main/templates/website/src/endpoints/seed/image-hero1.webp', 'https://raw.githubusercontent.com/payloadcms/payload/refs/heads/main/templates/website/src/endpoints/seed/image-hero1.webp',
), ),
]) ])
// Log all but not the buffer
req.payload.logger.info({
image1Buffer: {
name: image1Buffer.name,
mimetype: image1Buffer.mimetype,
size: image1Buffer.size,
},
image2Buffer: {
name: image2Buffer.name,
mimetype: image2Buffer.mimetype,
size: image2Buffer.size,
},
image3Buffer: {
name: image3Buffer.name,
mimetype: image3Buffer.mimetype,
size: image3Buffer.size,
},
hero1Buffer: {
name: hero1Buffer.name,
mimetype: hero1Buffer.mimetype,
size: hero1Buffer.size,
},
})
const image1Doc = await payload.create({ const image1Doc = await payload.create({
collection: 'media', collection: 'media',
data: image1, data: image1,
file: image1Buffer, file: image1Buffer,
req,
}) })
const image2Doc = await payload.create({ const image2Doc = await payload.create({
collection: 'media', collection: 'media',
@@ -150,13 +120,11 @@ export const seed = async ({
collection: 'media', collection: 'media',
data: image2, data: image2,
file: image3Buffer, file: image3Buffer,
req,
}) })
const imageHomeDoc = await payload.create({ const imageHomeDoc = await payload.create({
collection: 'media', collection: 'media',
data: image2, data: image2,
file: hero1Buffer, file: hero1Buffer,
req,
}) })
payload.logger.info(`— Seeding categories...`) payload.logger.info(`— Seeding categories...`)
@@ -165,7 +133,6 @@ export const seed = async ({
data: { data: {
title: 'Technology', title: 'Technology',
}, },
req,
}) })
const newsCategory = await payload.create({ const newsCategory = await payload.create({
@@ -173,7 +140,6 @@ export const seed = async ({
data: { data: {
title: 'News', title: 'News',
}, },
req,
}) })
const financeCategory = await payload.create({ const financeCategory = await payload.create({
@@ -181,7 +147,6 @@ export const seed = async ({
data: { data: {
title: 'Finance', title: 'Finance',
}, },
req,
}) })
await payload.create({ await payload.create({
@@ -189,7 +154,6 @@ export const seed = async ({
data: { data: {
title: 'Design', title: 'Design',
}, },
req,
}) })
await payload.create({ await payload.create({
@@ -197,7 +161,6 @@ export const seed = async ({
data: { data: {
title: 'Software', title: 'Software',
}, },
req,
}) })
await payload.create({ await payload.create({
@@ -205,7 +168,6 @@ export const seed = async ({
data: { data: {
title: 'Engineering', title: 'Engineering',
}, },
req,
}) })
let image1ID: number | string = image1Doc.id let image1ID: number | string = image1Doc.id
@@ -233,7 +195,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)) .replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)), .replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
), ),
req,
}) })
const post2Doc = await payload.create({ const post2Doc = await payload.create({
@@ -244,7 +205,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image3ID)) .replace(/"\{\{IMAGE_2\}\}"/g, String(image3ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)), .replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
), ),
req,
}) })
const post3Doc = await payload.create({ const post3Doc = await payload.create({
@@ -255,7 +215,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image1ID)) .replace(/"\{\{IMAGE_2\}\}"/g, String(image1ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)), .replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
), ),
req,
}) })
// update each post with related posts // update each post with related posts
@@ -265,7 +224,6 @@ export const seed = async ({
data: { data: {
relatedPosts: [post2Doc.id, post3Doc.id], relatedPosts: [post2Doc.id, post3Doc.id],
}, },
req,
}) })
await payload.update({ await payload.update({
id: post2Doc.id, id: post2Doc.id,
@@ -273,7 +231,6 @@ export const seed = async ({
data: { data: {
relatedPosts: [post1Doc.id, post3Doc.id], relatedPosts: [post1Doc.id, post3Doc.id],
}, },
req,
}) })
await payload.update({ await payload.update({
id: post3Doc.id, id: post3Doc.id,
@@ -281,7 +238,6 @@ export const seed = async ({
data: { data: {
relatedPosts: [post1Doc.id, post2Doc.id], relatedPosts: [post1Doc.id, post2Doc.id],
}, },
req,
}) })
payload.logger.info(`— Seeding home page...`) payload.logger.info(`— Seeding home page...`)
@@ -293,7 +249,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID)) .replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID))
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)), .replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)),
), ),
req,
}) })
payload.logger.info(`— Seeding contact form...`) payload.logger.info(`— Seeding contact form...`)
@@ -301,7 +256,6 @@ export const seed = async ({
const contactForm = await payload.create({ const contactForm = await payload.create({
collection: 'forms', collection: 'forms',
data: JSON.parse(JSON.stringify(contactFormData)), data: JSON.parse(JSON.stringify(contactFormData)),
req,
}) })
let contactFormID: number | string = contactForm.id let contactFormID: number | string = contactForm.id
@@ -317,7 +271,6 @@ export const seed = async ({
data: JSON.parse( data: JSON.parse(
JSON.stringify(contactPageData).replace(/"\{\{CONTACT_FORM_ID\}\}"/g, String(contactFormID)), JSON.stringify(contactPageData).replace(/"\{\{CONTACT_FORM_ID\}\}"/g, String(contactFormID)),
), ),
req,
}) })
payload.logger.info(`— Seeding header...`) payload.logger.info(`— Seeding header...`)
@@ -345,7 +298,6 @@ export const seed = async ({
}, },
], ],
}, },
req,
}) })
payload.logger.info(`— Seeding footer...`) payload.logger.info(`— Seeding footer...`)
@@ -379,7 +331,6 @@ export const seed = async ({
}, },
], ],
}, },
req,
}) })
payload.logger.info('Seeded database successfully!') payload.logger.info('Seeded database successfully!')

View File

@@ -48,7 +48,6 @@ export const seed = async ({
data: { data: {
navItems: [], navItems: [],
}, },
req,
}) })
} }
@@ -60,18 +59,14 @@ export const seed = async ({
exists: true, exists: true,
}, },
}, },
req,
}) })
} }
const pages = await payload.delete({ const pages = await payload.delete({
collection: 'pages', collection: 'pages',
where: {}, where: {},
req,
}) })
console.log({ pages })
payload.logger.info(`— Seeding demo author and user...`) payload.logger.info(`— Seeding demo author and user...`)
await payload.delete({ await payload.delete({
@@ -81,7 +76,6 @@ export const seed = async ({
equals: 'demo-author@payloadcms.com', equals: 'demo-author@payloadcms.com',
}, },
}, },
req,
}) })
const demoAuthor = await payload.create({ const demoAuthor = await payload.create({
@@ -91,7 +85,6 @@ export const seed = async ({
email: 'demo-author@payloadcms.com', email: 'demo-author@payloadcms.com',
password: 'password', password: 'password',
}, },
req,
}) })
let demoAuthorID: number | string = demoAuthor.id let demoAuthorID: number | string = demoAuthor.id
@@ -111,34 +104,11 @@ export const seed = async ({
'https://raw.githubusercontent.com/payloadcms/payload/refs/heads/main/templates/website/src/endpoints/seed/image-hero1.webp', 'https://raw.githubusercontent.com/payloadcms/payload/refs/heads/main/templates/website/src/endpoints/seed/image-hero1.webp',
), ),
]) ])
// Log all but not the buffer
req.payload.logger.info({
image1Buffer: {
name: image1Buffer.name,
mimetype: image1Buffer.mimetype,
size: image1Buffer.size,
},
image2Buffer: {
name: image2Buffer.name,
mimetype: image2Buffer.mimetype,
size: image2Buffer.size,
},
image3Buffer: {
name: image3Buffer.name,
mimetype: image3Buffer.mimetype,
size: image3Buffer.size,
},
hero1Buffer: {
name: hero1Buffer.name,
mimetype: hero1Buffer.mimetype,
size: hero1Buffer.size,
},
})
const image1Doc = await payload.create({ const image1Doc = await payload.create({
collection: 'media', collection: 'media',
data: image1, data: image1,
file: image1Buffer, file: image1Buffer,
req,
}) })
const image2Doc = await payload.create({ const image2Doc = await payload.create({
collection: 'media', collection: 'media',
@@ -150,13 +120,11 @@ export const seed = async ({
collection: 'media', collection: 'media',
data: image2, data: image2,
file: image3Buffer, file: image3Buffer,
req,
}) })
const imageHomeDoc = await payload.create({ const imageHomeDoc = await payload.create({
collection: 'media', collection: 'media',
data: image2, data: image2,
file: hero1Buffer, file: hero1Buffer,
req,
}) })
payload.logger.info(`— Seeding categories...`) payload.logger.info(`— Seeding categories...`)
@@ -165,7 +133,6 @@ export const seed = async ({
data: { data: {
title: 'Technology', title: 'Technology',
}, },
req,
}) })
const newsCategory = await payload.create({ const newsCategory = await payload.create({
@@ -173,7 +140,6 @@ export const seed = async ({
data: { data: {
title: 'News', title: 'News',
}, },
req,
}) })
const financeCategory = await payload.create({ const financeCategory = await payload.create({
@@ -181,7 +147,6 @@ export const seed = async ({
data: { data: {
title: 'Finance', title: 'Finance',
}, },
req,
}) })
await payload.create({ await payload.create({
@@ -189,7 +154,6 @@ export const seed = async ({
data: { data: {
title: 'Design', title: 'Design',
}, },
req,
}) })
await payload.create({ await payload.create({
@@ -197,7 +161,6 @@ export const seed = async ({
data: { data: {
title: 'Software', title: 'Software',
}, },
req,
}) })
await payload.create({ await payload.create({
@@ -205,7 +168,6 @@ export const seed = async ({
data: { data: {
title: 'Engineering', title: 'Engineering',
}, },
req,
}) })
let image1ID: number | string = image1Doc.id let image1ID: number | string = image1Doc.id
@@ -233,7 +195,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)) .replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)), .replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
), ),
req,
}) })
const post2Doc = await payload.create({ const post2Doc = await payload.create({
@@ -244,7 +205,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image3ID)) .replace(/"\{\{IMAGE_2\}\}"/g, String(image3ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)), .replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
), ),
req,
}) })
const post3Doc = await payload.create({ const post3Doc = await payload.create({
@@ -255,7 +215,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image1ID)) .replace(/"\{\{IMAGE_2\}\}"/g, String(image1ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)), .replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
), ),
req,
}) })
// update each post with related posts // update each post with related posts
@@ -265,7 +224,6 @@ export const seed = async ({
data: { data: {
relatedPosts: [post2Doc.id, post3Doc.id], relatedPosts: [post2Doc.id, post3Doc.id],
}, },
req,
}) })
await payload.update({ await payload.update({
id: post2Doc.id, id: post2Doc.id,
@@ -273,7 +231,6 @@ export const seed = async ({
data: { data: {
relatedPosts: [post1Doc.id, post3Doc.id], relatedPosts: [post1Doc.id, post3Doc.id],
}, },
req,
}) })
await payload.update({ await payload.update({
id: post3Doc.id, id: post3Doc.id,
@@ -281,7 +238,6 @@ export const seed = async ({
data: { data: {
relatedPosts: [post1Doc.id, post2Doc.id], relatedPosts: [post1Doc.id, post2Doc.id],
}, },
req,
}) })
payload.logger.info(`— Seeding home page...`) payload.logger.info(`— Seeding home page...`)
@@ -293,7 +249,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID)) .replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID))
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)), .replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)),
), ),
req,
}) })
payload.logger.info(`— Seeding contact form...`) payload.logger.info(`— Seeding contact form...`)
@@ -301,7 +256,6 @@ export const seed = async ({
const contactForm = await payload.create({ const contactForm = await payload.create({
collection: 'forms', collection: 'forms',
data: JSON.parse(JSON.stringify(contactFormData)), data: JSON.parse(JSON.stringify(contactFormData)),
req,
}) })
let contactFormID: number | string = contactForm.id let contactFormID: number | string = contactForm.id
@@ -317,7 +271,6 @@ export const seed = async ({
data: JSON.parse( data: JSON.parse(
JSON.stringify(contactPageData).replace(/"\{\{CONTACT_FORM_ID\}\}"/g, String(contactFormID)), JSON.stringify(contactPageData).replace(/"\{\{CONTACT_FORM_ID\}\}"/g, String(contactFormID)),
), ),
req,
}) })
payload.logger.info(`— Seeding header...`) payload.logger.info(`— Seeding header...`)
@@ -345,7 +298,6 @@ export const seed = async ({
}, },
], ],
}, },
req,
}) })
payload.logger.info(`— Seeding footer...`) payload.logger.info(`— Seeding footer...`)
@@ -379,7 +331,6 @@ export const seed = async ({
}, },
], ],
}, },
req,
}) })
payload.logger.info('Seeded database successfully!') payload.logger.info('Seeded database successfully!')