-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
52 lines (42 loc) · 939 Bytes
/
Copy pathclasses.js
File metadata and controls
52 lines (42 loc) · 939 Bytes
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
const { generateRandomString } = require('./helper');
// Class used to create URLS
class URL {
constructor(longURL, userID) {
this.longURL = longURL;
this.userID = userID;
this.createdOn = new Date();
this.visits = {
count : 0,
eachVisit : [],
uniqueVisitors : []
};
}
incrementCount() {
this.visits.count = this.visits.count + 1;
}
getUniqueVisits() {
return this.visits.uniqueVisitors.length;
}
getVisits() {
return this.visits.eachVisit;
}
addVisit(visitorId, time) {
this.visits.eachVisit.push({
visitorId,
time
});
this.incrementCount();
}
addUnique(visitorID) {
this.visits.uniqueVisitors.push(visitorID);
}
}
// Class used to create new Users
class User {
constructor(email, password) {
this.id = generateRandomString();
this.email = email;
this.password = password;
}
}
module.exports = { User, URL };