]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/typings/models/user/user.ts
Improve SQL query for my special playlists
[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 '../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 = MUser &
33 Use<'Account', MAccountId>
34
35 export type MUserAccountUrl = MUser &
36 Use<'Account', MAccountUrl & MAccountIdActorId>
37
38 export type MUserAccount = MUser &
39 Use<'Account', MAccount>
40
41 export type MUserAccountDefault = MUser &
42 Use<'Account', MAccountDefault>
43
44 // With channel
45
46 export type MUserNotifSettingChannelDefault = MUser &
47 Use<'NotificationSetting', MNotificationSetting> &
48 Use<'Account', MAccountDefaultChannelDefault>
49
50 // With notification settings
51
52 export type MUserWithNotificationSetting = MUser &
53 Use<'NotificationSetting', MNotificationSetting>
54
55 export type MUserNotifSettingAccount = MUser &
56 Use<'NotificationSetting', MNotificationSetting> &
57 Use<'Account', MAccount>
58
59 // Default scope
60
61 export type MUserDefault = MUser &
62 Use<'NotificationSetting', MNotificationSetting> &
63 Use<'Account', MAccountDefault>
64
65 // ############################################################################
66
67 // Format for API or AP object
68
69 type MAccountWithChannels = MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]>
70 type MAccountWithChannelsAndSpecialPlaylists = MAccountWithChannels &
71 PickWithOpt<AccountModel, 'VideoPlaylists', MVideoPlaylist[]>
72
73 export type MUserFormattable = MUserQuotaUsed &
74 Use<'Account', MAccountWithChannels> &
75 PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable>
76
77 export type MMyUserFormattable = MUserFormattable &
78 Use<'Account', MAccountWithChannelsAndSpecialPlaylists>