-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.ts
64 lines (59 loc) · 1.92 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import path from 'path';
import type { Payload } from 'payload';
import { pagesSlug } from '../collections/Pages';
import { mediaSlug } from '../collections/Media';
import { usersSlug } from '../collections/Users';
import home from './home-page.json';
import posts from './posts-page';
export const seedPages = async (payload: Payload) => {
const { totalDocs } = await payload.find({
collection: pagesSlug,
});
if (!totalDocs) {
const createdMedia = await payload.create({
collection: mediaSlug,
data: {
alt: 'Payload',
},
filePath: path.resolve(__dirname, './payload.jpg'),
});
const createdPostsPage = await payload.create({
collection: pagesSlug,
data: posts,
});
const publicString = JSON.stringify(home)
.replace(/{{IMAGE_ID}}/g, createdMedia.id.toString())
.replace(/{{SAMPLE_PAGE_ID}}/g, createdPostsPage.id.toString());
await payload.create({
collection: pagesSlug,
data: JSON.parse(publicString),
});
payload.logger.info(`Successfully seeded pages into database`);
}
};
export const seedUsers = async (payload: Payload) => {
const { totalDocs } = await payload.find({
collection: usersSlug,
});
if (!totalDocs) {
payload.create({
collection: usersSlug,
data: {
password: 'qwerty',
name: 'Admin User',
role: 'admin',
},
});
payload.create({
collection: usersSlug,
data: {
password: 'qwerty',
name: 'Frontend User',
role: 'user',
},
});
payload.logger.info(`Successfully seeded users into database`);
}
};