-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed-server.mjs
33 lines (33 loc) · 1011 Bytes
/
seed-server.mjs
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
import db from './models';
import users from './data/user-seeds';
import problems from './data/problem-seeds';
db.sequelize.sync({force: true}).then(() => {
var userPromises = [];
users.forEach(user => {
console.log(user);
userPromises.push(db.User.create({
id: user.id,
bcsId: user.bcsId,
avatarUrl: user.avatarUrl,
githubUserName: user.githubUserName
}))
});
Promise.all(userPromises).then(() => {
var problemPromises = [];
problems.forEach(problem => {
problemPromises.push(db.Problem.create({
imageUrl: problem.imageUrl,
name: problem.name,
description: problem.description,
short: problem.short,
hint: problem.hint
}, {
userId: problem.UserId
}));
});
Promise.all(problemPromises).then(() => {
console.log("finished!")
db.sequelize.close();
});
})
});