-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerateData.js
56 lines (51 loc) · 1.37 KB
/
generateData.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
const faker = require('faker');
module.exports = () => {
// for /todos
const todos = [];
for (let i = 0; i < 200; i++) {
todos.push({
id: i,
title: faker.lorem.sentence(),
order: i,
completed: Math.random() > 0.5 ? true : false,
createdAt: faker.date.between('2018-01-01', '2019-12-31').toISOString()
});
}
// generate related data for /users /posts /comments
const users = [];
for (let i = 0; i < 100; i++) {
users.push({
id: i,
firstName: faker.name.findName(),
lastName: faker.name.lastName(),
avatar: faker.image.avatar()
});
}
// a post belong to a userId
const posts = [];
for (let i = 0; i < 300; i++) {
posts.push({
uuid: faker.random.uuid(),
userId: faker.random.number({ min: 0, max: 20 }),
title: faker.lorem.sentence(),
createdAt: faker.date.between('2018-01-01', '2019-12-31').toISOString()
});
}
// a comment has author (userId) and postId
const comments = [];
for (let i = 0; i < 300; i++) {
comments.push({
uuid: faker.random.uuid(),
postId: faker.random.number({ min: 0, max: 20 }),
userId: faker.random.number({ min: 0, max: 20 }),
title: faker.lorem.sentence(),
createdAt: faker.date.between('2018-01-01', '2019-12-31').toISOString()
});
}
return {
todos,
users,
posts,
comments
};
};