Skip to content

Commit

Permalink
fix(templates): remove req from seed script
Browse files Browse the repository at this point in the history
  • Loading branch information
denolfe committed Nov 18, 2024
1 parent 7314990 commit ecbafbf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 100 deletions.
51 changes: 1 addition & 50 deletions templates/website/src/endpoints/seed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const seed = async ({
data: {
navItems: [],
},
req,
})
}

Expand All @@ -60,18 +59,14 @@ export const seed = async ({
exists: true,
},
},
req,
})
}

const pages = await payload.delete({
collection: 'pages',
where: {},
req,
})

console.log({ pages })

payload.logger.info(`— Seeding demo author and user...`)

await payload.delete({
Expand All @@ -81,7 +76,6 @@ export const seed = async ({
equals: 'demo-author@payloadcms.com',
},
},
req,
})

const demoAuthor = await payload.create({
Expand All @@ -91,7 +85,6 @@ export const seed = async ({
email: 'demo-author@payloadcms.com',
password: 'password',
},
req,
})

let demoAuthorID: number | string = demoAuthor.id
Expand All @@ -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',
),
])
// 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({
collection: 'media',
data: image1,
file: image1Buffer,
req,
})
const image2Doc = await payload.create({
collection: 'media',
Expand All @@ -150,13 +120,11 @@ export const seed = async ({
collection: 'media',
data: image2,
file: image3Buffer,
req,
})
const imageHomeDoc = await payload.create({
collection: 'media',
data: image2,
file: hero1Buffer,
req,
})

payload.logger.info(`— Seeding categories...`)
Expand All @@ -165,47 +133,41 @@ export const seed = async ({
data: {
title: 'Technology',
},
req,
})

const newsCategory = await payload.create({
collection: 'categories',
data: {
title: 'News',
},
req,
})

const financeCategory = await payload.create({
collection: 'categories',
data: {
title: 'Finance',
},
req,
})

await payload.create({
collection: 'categories',
data: {
title: 'Design',
},
req,
})

await payload.create({
collection: 'categories',
data: {
title: 'Software',
},
req,
})

await payload.create({
collection: 'categories',
data: {
title: 'Engineering',
},
req,
})

let image1ID: number | string = image1Doc.id
Expand Down Expand Up @@ -233,7 +195,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
),
req,
})

const post2Doc = await payload.create({
Expand All @@ -244,7 +205,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image3ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
),
req,
})

const post3Doc = await payload.create({
Expand All @@ -255,7 +215,6 @@ export const seed = async ({
.replace(/"\{\{IMAGE_2\}\}"/g, String(image1ID))
.replace(/"\{\{AUTHOR\}\}"/g, String(demoAuthorID)),
),
req,
})

// update each post with related posts
Expand All @@ -265,23 +224,20 @@ export const seed = async ({
data: {
relatedPosts: [post2Doc.id, post3Doc.id],
},
req,
})
await payload.update({
id: post2Doc.id,
collection: 'posts',
data: {
relatedPosts: [post1Doc.id, post3Doc.id],
},
req,
})
await payload.update({
id: post3Doc.id,
collection: 'posts',
data: {
relatedPosts: [post1Doc.id, post2Doc.id],
},
req,
})

payload.logger.info(`— Seeding home page...`)
Expand All @@ -293,15 +249,13 @@ export const seed = async ({
.replace(/"\{\{IMAGE_1\}\}"/g, String(imageHomeID))
.replace(/"\{\{IMAGE_2\}\}"/g, String(image2ID)),
),
req,
})

payload.logger.info(`— Seeding contact form...`)

const contactForm = await payload.create({
collection: 'forms',
data: JSON.parse(JSON.stringify(contactFormData)),
req,
})

let contactFormID: number | string = contactForm.id
Expand All @@ -317,7 +271,6 @@ export const seed = async ({
data: JSON.parse(
JSON.stringify(contactPageData).replace(/"\{\{CONTACT_FORM_ID\}\}"/g, String(contactFormID)),
),
req,
})

payload.logger.info(`— Seeding header...`)
Expand Down Expand Up @@ -345,7 +298,6 @@ export const seed = async ({
},
],
},
req,
})

payload.logger.info(`— Seeding footer...`)
Expand Down Expand Up @@ -379,7 +331,6 @@ export const seed = async ({
},
],
},
req,
})

payload.logger.info('Seeded database successfully!')
Expand Down
Loading

0 comments on commit ecbafbf

Please sign in to comment.