Skip to content

Commit 9709f08

Browse files
committed
feat: post seed
1 parent b42ae2b commit 9709f08

File tree

2 files changed

+37
-6
lines changed
  • apps/web/app/[lang]/(public-fullwidth)/author/[authorId]
  • packages/database/prisma/seeds

2 files changed

+37
-6
lines changed

apps/web/app/[lang]/(public-fullwidth)/author/[authorId]/page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ export const metadata = {
1414

1515
export default async function Page({ params, searchParams }) {
1616
const { data, total } = await getPosts({
17-
searchParams: {
18-
authorId: params?.authorId,
19-
...searchParams,
20-
},
17+
authorId: params?.authorId,
18+
...searchParams,
2119
})
2220

2321
return (

packages/database/prisma/seeds/seed.mjs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { PrismaClient } from "@prisma/client"
2+
import posts from "./posts.json" assert { type: "json" }
3+
import slugify from "slugify"
24

35
const prisma = new PrismaClient()
46

@@ -15,9 +17,40 @@ async function main() {
1517
update: {},
1618
})
1719

18-
console.log("seed-user:", { user })
20+
for (const post of posts) {
21+
await prisma.post.create({
22+
data: {
23+
title: post.title || '',
24+
content: post.description,
25+
slug: slugify(post.title || '-') + new Date().getTime(),
26+
author: {
27+
connect: {
28+
id: user.id,
29+
},
30+
},
31+
image: {
32+
create: {
33+
url: post.image_url || '',
34+
path: post.image_url || '',
35+
name: post.title || '',
36+
mime: "",
37+
hash: "",
38+
ext: "",
39+
width: 0,
40+
height: 0,
41+
format: "",
42+
user: {
43+
connect: {
44+
id: user.id,
45+
}
46+
}
47+
},
48+
},
49+
},
50+
})
51+
}
1952
}
2053

2154
main().then(() => {
22-
console.log("User created successfully")
55+
console.log("Seed has been created")
2356
})

0 commit comments

Comments
 (0)