-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathseed.js
46 lines (40 loc) · 1.3 KB
/
seed.js
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
'use strict'
const exampleData = [
{
user: {
username: 'manuel.lo',
displayName: 'Manuel'
},
tasks: [
{ description: 'Write grocery list', priority: 3 },
{ description: 'Fix kitchen tap', priority: 1 },
{ description: 'Buy plants', priority: 1 },
{ description: 'Go for a swim', priority: 2 },
{ description: 'Practice playing guitar', priority: 3 }
]
},
{
user: {
username: 'charlie37',
displayName: 'Charlie B'
},
tasks: [
{ description: 'Buy dog snacks', priority: 2 },
{ description: 'Submit article for review', priority: 2 },
{ description: 'Return faulty headphones', priority: 2 },
{ description: 'Walk the dog', priority: 1 },
{ description: 'Go for a run', priority: 3 },
{ description: 'Plan summer vacation', priority: 2 },
{ description: 'Order new headphones', priority: 3 }
]
}
]
module.exports = async function ({ entities }) {
for (const { user, tasks } of exampleData) {
const newUser = await entities.user.save({ input: user })
console.log('Created user:', newUser)
const userTasks = tasks.map(task => ({ ...task, userId: newUser.id }))
const newTasks = await entities.task.insert({ inputs: userTasks })
console.log('Created tasks:', newTasks)
}
}