-
Notifications
You must be signed in to change notification settings - Fork 4
/
user.ts
88 lines (79 loc) · 1.65 KB
/
user.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
type PreferenceType = {
theme?: string;
};
/**
* Represents a user in the system.
*/
export class User {
/**
* Creates a new User.
* @param {string} username for the user
* @param {string} role role for the user
* @param {string} id unique id for the user
* @param {PreferenceType} preferences any user preferences
*/
constructor(
private username: string = '',
private role: string = '',
private id: string = '',
private preferences?: PreferenceType | null
) {
this.preferences = preferences || null;
}
/**
* Get username
* @returns {string} the username
*/
getUsername(): string {
return this.username;
}
/**
* Set username
* @param {string} username the new username
*/
setUsername(username: string): void {
this.username = username;
}
/**
* Get user rols
* @returns {string} the user role
*/
getRole(): string {
return this.role;
}
/**
* Set user role
* @param {string} role the new user role
*/
setRole(role: string): void {
this.role = role;
}
/**
* Get user id
* @returns {string} the unique user id
*/
getId(): string {
return this.id;
}
/**
* Set user id
* @param {string} id unique id for the user
*/
setId(id: string): void {
this.id = id;
}
/**
* Get user preferences
* @returns {PreferenceType} a shallow copy of the user preferences
*/
getPreferences(): PreferenceType {
return { ...this.preferences };
}
/**
* Set user preferences
* @param {PreferenceType} prefs preferences for the user
*/
setPreferences(prefs: PreferenceType): void {
this.preferences = prefs;
}
}