-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.js
50 lines (36 loc) · 992 Bytes
/
users.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
class Users {
constructor() {
this.users = [];
}
// aad user
addUser(id,name,currentOrder,orderHistory,seenMenuList){
let user = {id,name,currentOrder:[],orderHistory:[],seenMenuList:'No'};
this.users.push(user);
return user;
}
// gets a user with id
getUser(id) {
return this.users.filter((user) => user.id === id)[0];
}
// add order to current order
addCurrentOrder(id,order) {
let user = this.getUser(id);
user.currentOrder.push(order)
return user
}
// add current orders to history
addOrderToHistory(id){
let user = this.getUser(id)
user.currentOrder.forEach(element => {
user.orderHistory.push(element)
});
return user
}
// deletes current order
deleteCurrentOrder(id){
let user = this.getUser(id)
user.currentOrder.length = 0
return user
}
}
module.exports = {Users};