forked from eecs130/json-server-heroku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockdata.js
57 lines (52 loc) · 1.43 KB
/
mockdata.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
// https://www.npmjs.com/package/casual
// https://www.npmjs.com/package/faker
const casual = require('casual');
const faker = require('faker');
// Create an object for config file
const db = {
//books:[],
users: [],
posts: [],
comments: []
};
for (let i=1; i <= 5; i++) {
// books:
// db.books.push({
// id: i,
// title: casual.words(casual.integer(1,6)),
// author: casual.first_name + ' ' + casual.last_name,
// rating: Math.floor(Math.random()*100+1)/20,
// year_published: casual.integer(1700,2019)
// });
// users:
db.users.push({
id: i,
email: casual.email,
firstname: casual.first_name,
lastname: casual.last_name,
password: casual.password,
avatar: faker.image.avatar()
})
// blog posts
db.posts.push({
id: i,
title: casual.title,
body: casual.sentences(n=casual.integer(10,20)),
user_id: casual.integer(1,10),
date: casual.date(format = 'YYYY-MM-DD'),
images: [
faker.random.image(),
faker.random.image()
]
})
// comments
for (let j=1; j <= casual.integer(1,5); j++) {
db.comments.push({
id: db.comments.length + 1,
post_id: i,
body: casual.sentences(n=casual.integer(2,10)),
date: casual.date(format = 'YYYY-MM-DD')
})
}
}
console.log(JSON.stringify(db));