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