-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.js
47 lines (41 loc) · 1.08 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
class User {
constructor(firstName, lastName, address, phone, education, email, password, age, country) {
this.firstName = firstName
this.lastName = lastName
this.address = address
this.phone = phone
this.education = education
this.email = email
this.password = password
this.age = age
this.country = country
}
}
class UserDAO {
constructor() {
this.users = [
new User('Anakin', 'Skywalker', 'Downing St. 10', '6912345678', 'Master', '[email protected]', 'testing321', 23, 'Greece'),
]
}
getUser(email) {
for (let user of this.users) {
if (email == user.email) {
return user
}
}
return null
}
getAllUsers() {
return this.users
}
addUser(user) {
const index = users.findIndex((User) => User.email === user.email)
if (index == -1) {
this.users.push(user)
return -1
} else {
return 0
}
}
}
module.exports = { User, UserDAO }