-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-mock-data.js
executable file
·88 lines (82 loc) · 1.86 KB
/
create-mock-data.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const {
models,
sequelize
} = require('./models');
function createData () {
let usersPromise = models.User.bulkCreate([{
login: 'veged',
avatarUrl: 'https://avatars3.githubusercontent.com/u/15365?s=460&v=4',
homeFloor: 0
},
{
login: 'alt-j',
avatarUrl: 'https://avatars1.githubusercontent.com/u/3763844?s=400&v=4',
homeFloor: 3
},
{
login: 'yeti-or',
avatarUrl: 'https://avatars0.githubusercontent.com/u/1813468?s=460&v=4',
homeFloor: 2
}
]);
let roomsPromise = models.Room.bulkCreate([{
title: '404',
capacity: 5,
floor: 4
},
{
title: 'Деньги',
capacity: 4,
floor: 2
},
{
title: 'Карты',
capacity: 4,
floor: 2
},
{
title: 'Ствола',
capacity: 2,
floor: 2
},
{
title: '14',
capacity: 6,
floor: 3
}
]);
const HOUR = 60 * 60 * 1000;
let now = new Date();
let oneHourLater = new Date(now.getTime() + HOUR);
let twoHoursLater = new Date(oneHourLater.getTime() + HOUR);
let threeHoursLater = new Date(twoHoursLater.getTime() + HOUR);
let eventsPromise = models.Event.bulkCreate([{
title: 'ШРИ 2018 - начало',
dateStart: now,
dateEnd: oneHourLater
},
{
title: '👾 Хакатон 👾',
dateStart: oneHourLater,
dateEnd: twoHoursLater
},
{
title: '🍨 Пробуем kefir.js',
dateStart: threeHoursLater,
dateEnd: twoHoursLater
}
]);
Promise.all([usersPromise, roomsPromise, eventsPromise])
.then(function ([users, rooms, events]) {
return Promise.all([
events[0].setRoom(rooms[0]),
events[1].setRoom(rooms[1]),
events[2].setRoom(rooms[2]),
events[0].setUsers([users[0], users[1]]),
events[1].setUsers([users[1], users[2]]),
events[2].setUsers([users[0], users[2]])
]);
});
}
sequelize.sync()
.then(createData);