-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
38 lines (36 loc) · 956 Bytes
/
seeds.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
const faker = require("faker");
const User = require("./models/user");
const Post = require("./models/post");
const Comment = require("./models/comment");
// create 200 new users with a random post and comment for each of them
const seedDb = (req, res, next) => {
for (let i = 0; i < 200; i++) {
new User({
name: faker.name.findName(),
photoURL: faker.image.imageUrl(),
githubId: faker.random.number(),
}).save((err, user) => {
if (err) {
return next(err);
}
new Post({
user: user.id,
content: faker.lorem.paragraph(),
}).save((err, post) => {
if (err) {
return next(err);
}
new Comment({
post: post.id,
content: faker.lorem.paragraph(),
user: user.id,
}).save((err, comment) => {
if (err) {
return next(err);
}
});
});
});
}
};
module.exports = seedDb;