-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.js
55 lines (45 loc) · 1.4 KB
/
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
var faker = require("faker");
faker.seed(100);
var categories = ["Watersports", "Soccer", "Chess"];
// Generate products
var products = [];
for (let i = 1; i <= 503; i++) {
var category = faker.helpers.randomize(categories);
products.push({
id: i,
name: faker.commerce.productName(),
category: category,
description: `${category}: ${faker.lorem.sentence(3)}`,
price: Number(faker.commerce.price()),
});
}
// Generate orders
var orders = [];
for(let i = 0; i <= 103; i++) {
var fname = faker.name.firstName()
var sname = faker.name.lastName();
var order = {
id: i, name: `${fname} ${sname}`,
email: faker.internet.email(fname, sname),
address: faker.address.streetAddress(), city: faker.address.city(),
zip: faker.address.zipCode(), country: faker.address.country(),
shipped: faker.random.boolean(),
products: []
}
var productCount = faker.random.number({ min: 1, max: 5 })
var product_ids = [];
while(product_ids.length < productCount) {
var candidateId = faker.random.number({ min: 1, max: products.length });
if(product_ids.indexOf(candidateId) === -1) {
product_ids.push(candidateId)
}
}
for(let j = 0; j < productCount; j++) {
order.products.push({
quantity: faker.random.number({ min: 1, max: 10 }),
product_id: product_ids[j]
})
}
orders.push(order)
}
module.exports = () => ({ categories, products, orders });