-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUser.js
68 lines (61 loc) · 1.37 KB
/
User.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
// Load database
const DB = require("./DB.js");
class User {
constructor(id = -1 ,points = 0){
this.id = id;
this.points = points;
this.birthday = -1; //default birthday to -1 to show unset
}
// GET
getID(){
return this.id;
}
getPoints(){
return this.points;
}
getBDay(){
return this.birthday;
}
// SET
setID(id){
this.id = id;
}
setPoints(points){
this.points = points;
}
setBDay(birthday){
if (this.checkDateFormat(birthday)) {
this.birthday = birthday;
return true;
}else{
return false;
}
}
// DB
// Cheak if the user exists in the db
isExists(){
return DB.isUserExist(this.id);
}
// Save user to db
save(){
DB.setPoints(this.id, this.points);
DB.setBirthday(this.id, this.birthday);
return;
}
// Load user from db
load(){
this.points = DB.getPoints(this.id);
this.birthday = DB.getBirthday(this.id);
return;
}
//utilitys
checkDateFormat(mydate){
var iso_format = /^(\d{4})-([0-1]\d)-([0-3]\d)$/;
var parts = String(mydate).match(iso_format);
if (parts == null) {
return false; // not a valid format
}
return true;
}
}
module.exports = User;