-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
75 lines (58 loc) · 1.25 KB
/
store.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var uuid = require('node-uuid');
var getRawBody = require('raw-body');
var items = {
"0" : {
name : "Revista sombrillas de hoy",
single : false,
numberPayments : 3,
amountPerPayment : 200
},
"1" : {
name : "Sombrilla roja",
single : true,
numberPayments : 1,
amountPerPayment : 200
}
}
var purchases = {};
exports.getItems = function(){
return items;
}
var Purchase = function(itemId){
var currentItem = items[itemId];
this.itemId = itemId;
this.item = currentItem;
this.single = true;
this.amount = currentItem.amountPerPayment;
this.paymentsLeft = currentItem.numberPayments;
this.setPreKey = function(preKey){
this.single = false;
this._preKey = preKey;
}
this.getPreKey = function(preKey){
if(!this.single){
return this._preKey;
}
}
this.doPay = function(){
this.paymentsLeft--;
}
}
exports.addItem = function(item){
var id = uuid.v4();
items[id] = item;
}
exports.getItem = function(id){
return items[id];
};
exports.addPurchase = function(id, itemId){
purchases[id] = new Purchase(itemId);
return id;
}
exports.getPurchase = function(pId){
console.log(purchases);
return purchases[pId];
}
exports.getPurchases = function(){
return purchases;
}