]>
Commit | Line | Data |
---|---|---|
404b54e1 C |
1 | import { |
2 | User as UserServerModel, | |
3 | UserRole, | |
954605a8 C |
4 | VideoChannel, |
5 | UserRight, | |
6 | hasUserRight | |
404b54e1 | 7 | } from '../../../../../shared' |
69f616ab | 8 | |
404b54e1 C |
9 | export type UserConstructorHash = { |
10 | id: number, | |
11 | username: string, | |
12 | email: string, | |
13 | role: UserRole, | |
14 | videoQuota?: number, | |
15 | displayNSFW?: boolean, | |
16 | createdAt?: Date, | |
1e1265b3 | 17 | account?: { |
404b54e1 C |
18 | id: number |
19 | uuid: string | |
20 | }, | |
21 | videoChannels?: VideoChannel[] | |
22 | } | |
69f616ab | 23 | export class User implements UserServerModel { |
df98563e C |
24 | id: number |
25 | username: string | |
26 | email: string | |
27 | role: UserRole | |
28 | displayNSFW: boolean | |
b0f9f39e | 29 | videoQuota: number |
1e1265b3 | 30 | account: { |
404b54e1 C |
31 | id: number |
32 | uuid: string | |
33 | } | |
34 | videoChannels: VideoChannel[] | |
df98563e | 35 | createdAt: Date |
7da18e44 | 36 | |
404b54e1 | 37 | constructor (hash: UserConstructorHash) { |
df98563e C |
38 | this.id = hash.id |
39 | this.username = hash.username | |
40 | this.email = hash.email | |
41 | this.role = hash.role | |
1e1265b3 | 42 | this.account = hash.account |
404b54e1 C |
43 | |
44 | if (hash.videoChannels !== undefined) { | |
45 | this.videoChannels = hash.videoChannels | |
46 | } | |
44c5275e | 47 | |
b0f9f39e C |
48 | if (hash.videoQuota !== undefined) { |
49 | this.videoQuota = hash.videoQuota | |
50 | } | |
51 | ||
52 | if (hash.displayNSFW !== undefined) { | |
53 | this.displayNSFW = hash.displayNSFW | |
54 | } | |
55 | ||
56 | if (hash.createdAt !== undefined) { | |
df98563e | 57 | this.createdAt = hash.createdAt |
44c5275e | 58 | } |
7da18e44 C |
59 | } |
60 | ||
954605a8 C |
61 | hasRight (right: UserRight) { |
62 | return hasUserRight(this.role, right) | |
7da18e44 C |
63 | } |
64 | } |