-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.js
34 lines (29 loc) · 927 Bytes
/
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
class User {
constructor(username, password, role, users) {
const Role = {
admin: "admin",
manager: "manager",
user: "user",
};
if (!username || !password || !role) {
throw new Error("The fields username, password and role are required");
}
if (
typeof username !== "string" ||
typeof password !== "string" ||
typeof role !== "string"
)
throw new Error("The fields username, password and role must be strings");
if (role !== Role.admin && role !== Role.manager && role !== Role.user)
throw new Error("The field role must be one of admin, manager or user");
if (users && !Array.isArray(users))
throw new Error(
"The field users must be an array of strings type username"
);
this.username = username;
this.password = password;
this.role = role;
this.users = users || [];
}
}
module.exports = User;