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