31cf075effcdcb60feeedfaa79d4332a20f56669
[oweals/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 '../video/video-channels'
15 import { MVideoPlaylist } from '@server/typings/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>