-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-mock-data.js
executable file
·120 lines (112 loc) · 2.75 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
},
{
login: 'batman',
avatarUrl: 'https://d30y9cdsu7xlg0.cloudfront.net/png/157453-200.png',
homeFloor: 7
},
{
login: 'lex-luthor',
avatarUrl: 'https://i.pinimg.com/736x/d4/99/3e/d4993e398ecb4b4944292c46966fac80--lex-luthor-superman-the-creation.jpg',
homeFloor: 5
},
]);
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: 5
},
{
title: '14',
capacity: 6,
floor: 7
},
{
title: 'Ржавый Фред',
capacity: 6,
floor: 7
},
{
title: 'Джокер',
capacity: 6,
floor: 6
},
]);
const HOUR = 60 * 60 * 1000;
let now = new Date();
now.setHours(12);
now.setMinutes(30);
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([
{
id:1,
title: 'ШРИ 2018 - начало',
dateStart: now,
dateEnd: oneHourLater
},
{
id:2,
title: '👾 Хакатон 👾',
dateStart: oneHourLater,
dateEnd: twoHoursLater
},
{
id:3,
title: '🍨 Пробуем kefir.js',
dateStart: twoHoursLater,
dateEnd: threeHoursLater
}
]);
Promise.all([usersPromise, roomsPromise, eventsPromise])
.then(() => Promise.all([
models.User.findAll(),
models.Room.findAll(),
models.Event.findAll()
]))
.then(function ([users, rooms, events]) {
let promises = [];
promises.push(events[0].setRoom(rooms[3]));
promises.push(events[1].setRoom(rooms[1]));
promises.push(events[2].setRoom(rooms[2]));
promises.push(events[0].setUsers([users[0], users[1]]));
promises.push(events[1].setUsers([users[1], users[2]]));
promises.push(events[2].setUsers([users[0], users[2]]));
return Promise.all(promises);
});
}
sequelize.sync()
.then(createData);