-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.class.ts
More file actions
61 lines (57 loc) · 1.29 KB
/
Copy pathrole.class.ts
File metadata and controls
61 lines (57 loc) · 1.29 KB
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
import { Role } from "../interfaces/role.interface";
export class RoleFactory {
static createRole(roleType: string): Role {
switch (roleType.toLowerCase()) {
case "admin":
return new Admin();
case "user":
return new User();
case "guest":
return new Guest();
default:
throw new Error(`Role type ${roleType} is not recognized.`);
}
}
}
export class Admin implements Role {
private permissions: string[];
private name: string;
constructor() {
this.permissions = ["read", "write", "delete", "update"];
this.name = "Admin";
}
getPermissions(): string[] {
return this.permissions;
}
isSameRole(role: string): boolean {
return role === this.name;
}
}
export class User implements Role {
private permissions: string[];
private name: string;
constructor() {
this.permissions = ["read", "write", "delete", "update"];
this.name = "User";
}
getPermissions(): string[] {
return this.permissions;
}
isSameRole(role: string): boolean {
return role === this.name;
}
}
export class Guest implements Role {
private permissions: string[];
private name: string;
constructor() {
this.permissions = ["read"];
this.name = "Guest";
}
getPermissions(): string[] {
return this.permissions;
}
isSameRole(role: string): boolean {
return role === this.name;
}
}