diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-18 10:45:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-18 10:46:27 +0200 |
commit | 26d6bf6533023326fa017812cf31bbe20c752d36 (patch) | |
tree | 9c4e3ecdc344420190f17d429bdf05d78fae7a8c /server/types/models/user/user.ts | |
parent | d6d951ddc0c492f3261065b5dcb4df0534d252fc (diff) | |
download | PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.tar.gz PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.tar.zst PeerTube-26d6bf6533023326fa017812cf31bbe20c752d36.zip |
Split types and typings
Diffstat (limited to 'server/types/models/user/user.ts')
-rw-r--r-- | server/types/models/user/user.ts | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/server/types/models/user/user.ts b/server/types/models/user/user.ts new file mode 100644 index 000000000..7938ea288 --- /dev/null +++ b/server/types/models/user/user.ts | |||
@@ -0,0 +1,89 @@ | |||
1 | import { UserModel } from '../../../models/account/user' | ||
2 | import { PickWith, PickWithOpt } from '../../utils' | ||
3 | import { | ||
4 | MAccount, | ||
5 | MAccountDefault, | ||
6 | MAccountDefaultChannelDefault, | ||
7 | MAccountFormattable, | ||
8 | MAccountId, | ||
9 | MAccountIdActorId, | ||
10 | MAccountUrl | ||
11 | } from '../account' | ||
12 | import { MNotificationSetting, MNotificationSettingFormattable } from './user-notification-setting' | ||
13 | import { AccountModel } from '@server/models/account/account' | ||
14 | import { MChannelFormattable } from '../video/video-channels' | ||
15 | import { MVideoPlaylist } from '@server/types/models' | ||
16 | |||
17 | type Use<K extends keyof UserModel, M> = PickWith<UserModel, K, M> | ||
18 | |||
19 | // ############################################################################ | ||
20 | |||
21 | export type MUser = Omit<UserModel, 'Account' | 'NotificationSetting' | 'VideoImports' | 'OAuthTokens'> | ||
22 | |||
23 | // ############################################################################ | ||
24 | |||
25 | export type MUserQuotaUsed = MUser & { videoQuotaUsed?: number, videoQuotaUsedDaily?: number } | ||
26 | export type MUserId = Pick<UserModel, 'id'> | ||
27 | |||
28 | // ############################################################################ | ||
29 | |||
30 | // With account | ||
31 | |||
32 | export type MUserAccountId = | ||
33 | MUser & | ||
34 | Use<'Account', MAccountId> | ||
35 | |||
36 | export type MUserAccountUrl = | ||
37 | MUser & | ||
38 | Use<'Account', MAccountUrl & MAccountIdActorId> | ||
39 | |||
40 | export type MUserAccount = | ||
41 | MUser & | ||
42 | Use<'Account', MAccount> | ||
43 | |||
44 | export type MUserAccountDefault = | ||
45 | MUser & | ||
46 | Use<'Account', MAccountDefault> | ||
47 | |||
48 | // With channel | ||
49 | |||
50 | export type MUserNotifSettingChannelDefault = | ||
51 | MUser & | ||
52 | Use<'NotificationSetting', MNotificationSetting> & | ||
53 | Use<'Account', MAccountDefaultChannelDefault> | ||
54 | |||
55 | // With notification settings | ||
56 | |||
57 | export type MUserWithNotificationSetting = | ||
58 | MUser & | ||
59 | Use<'NotificationSetting', MNotificationSetting> | ||
60 | |||
61 | export type MUserNotifSettingAccount = | ||
62 | MUser & | ||
63 | Use<'NotificationSetting', MNotificationSetting> & | ||
64 | Use<'Account', MAccount> | ||
65 | |||
66 | // Default scope | ||
67 | |||
68 | export type MUserDefault = | ||
69 | MUser & | ||
70 | Use<'NotificationSetting', MNotificationSetting> & | ||
71 | Use<'Account', MAccountDefault> | ||
72 | |||
73 | // ############################################################################ | ||
74 | |||
75 | // Format for API or AP object | ||
76 | |||
77 | type MAccountWithChannels = MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]> | ||
78 | type MAccountWithChannelsAndSpecialPlaylists = | ||
79 | MAccountWithChannels & | ||
80 | PickWithOpt<AccountModel, 'VideoPlaylists', MVideoPlaylist[]> | ||
81 | |||
82 | export type MUserFormattable = | ||
83 | MUserQuotaUsed & | ||
84 | Use<'Account', MAccountWithChannels> & | ||
85 | PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable> | ||
86 | |||
87 | export type MMyUserFormattable = | ||
88 | MUserFormattable & | ||
89 | Use<'Account', MAccountWithChannelsAndSpecialPlaylists> | ||