-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstoreitems.js
61 lines (53 loc) · 1.59 KB
/
storeitems.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
58
59
60
61
module.exports = (function(){
let items = [];
const item = function(payload) {
this.img = payload.img;
this.alt = payload.alt;
this.name = payload.name;
this.price = payload.price;
this.description = payload.description;
this.categoryId = payload.categoryId;
this.weight = payload.weight;
this.height = payload.height;
this.width = payload.width;
this.depth = payload.depth;
}
const flavors = [ 'Mint', 'Peppermint', 'Frankincense', 'Lavender', 'Tea Tree', 'Lemon', 'Sage', 'Clove'];
return {
getItems: function(page, number) {
let start = (page - 1) * number;
let end = page * number;
if (end >= items.length) {
end = items.length -1;
}
return items.slice(start, end);
},
setItems: function(newItems) {
items = newItems;
},
getItemsLength: function() {
return items.length;
},
initTestItems: function(n) {
// if (items != []) return;
for (let i = 0; i < n; i++) {
let flavor = Math.floor(Math.random() * flavors.length);
let cost = (Math.random() * 2) + 4;
let itemPayload = {
img: './joanna-kosinska-Prfs32wh-o4-unsplash.jpg',
alt: 'A spoon-full of salt',
name: `${flavors[flavor]} Salt`,
price: cost.toFixed(2),
description: `${flavors[flavor]} Salt for rejuvenation and relaxation.`,
categoryId: 1,
weight: 3,
height: 10,
width: 6,
depth: 2.5
}
let newItem = new item(itemPayload);
items.push(newItem);
}
}
}
}());