]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/typings/models/user/user.ts
Type toFormattedJSON
[github/Chocobozzz/PeerTube.git] / server / typings / models / user / user.ts
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 '@server/typings/models'
15
16 type Use<K extends keyof UserModel, M> = PickWith<UserModel, K, M>
17
18 // ############################################################################
19
20 export type MUser = Omit<UserModel, 'Account' | 'NotificationSetting' | 'VideoImports' | 'OAuthTokens'>
21
22 // ############################################################################
23
24 export type MUserQuotaUsed = MUser & { videoQuotaUsed?: number, videoQuotaUsedDaily?: number }
25 export type MUserId = Pick<UserModel, 'id'>
26
27 // ############################################################################
28
29 // With account
30
31 export type MUserAccountId = MUser &
32 Use<'Account', MAccountId>
33
34 export type MUserAccountUrl = MUser &
35 Use<'Account', MAccountUrl & MAccountIdActorId>
36
37 export type MUserAccount = MUser &
38 Use<'Account', MAccount>
39
40 export type MUserAccountDefault = MUser &
41 Use<'Account', MAccountDefault>
42
43 // With channel
44
45 export type MUserNotifSettingChannelDefault = MUser &
46 Use<'NotificationSetting', MNotificationSetting> &
47 Use<'Account', MAccountDefaultChannelDefault>
48
49 // With notification settings
50
51 export type MUserWithNotificationSetting = MUser &
52 Use<'NotificationSetting', MNotificationSetting>
53
54 export type MUserNotifSettingAccount = MUser &
55 Use<'NotificationSetting', MNotificationSetting> &
56 Use<'Account', MAccount>
57
58 // Default scope
59
60 export type MUserDefault = MUser &
61 Use<'NotificationSetting', MNotificationSetting> &
62 Use<'Account', MAccountDefault>
63
64 // ############################################################################
65
66 // Format for API or AP object
67
68 export type MUserFormattable = MUserQuotaUsed &
69 Use<'Account', MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]>> &
70 PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable>