user.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. type Use<K extends keyof UserModel, M> = PickWith<UserModel, K, M>
  16. // ############################################################################
  17. export type MUser = Omit<UserModel, 'Account' | 'NotificationSetting' | 'VideoImports' | 'OAuthTokens'>
  18. // ############################################################################
  19. export type MUserQuotaUsed = MUser & { videoQuotaUsed?: number, videoQuotaUsedDaily?: number }
  20. export type MUserId = Pick<UserModel, 'id'>
  21. // ############################################################################
  22. // With account
  23. export type MUserAccountId = MUser &
  24. Use<'Account', MAccountId>
  25. export type MUserAccountUrl = MUser &
  26. Use<'Account', MAccountUrl & MAccountIdActorId>
  27. export type MUserAccount = MUser &
  28. Use<'Account', MAccount>
  29. export type MUserAccountDefault = MUser &
  30. Use<'Account', MAccountDefault>
  31. // With channel
  32. export type MUserNotifSettingChannelDefault = MUser &
  33. Use<'NotificationSetting', MNotificationSetting> &
  34. Use<'Account', MAccountDefaultChannelDefault>
  35. // With notification settings
  36. export type MUserWithNotificationSetting = MUser &
  37. Use<'NotificationSetting', MNotificationSetting>
  38. export type MUserNotifSettingAccount = MUser &
  39. Use<'NotificationSetting', MNotificationSetting> &
  40. Use<'Account', MAccount>
  41. // Default scope
  42. export type MUserDefault = MUser &
  43. Use<'NotificationSetting', MNotificationSetting> &
  44. Use<'Account', MAccountDefault>
  45. // ############################################################################
  46. // Format for API or AP object
  47. export type MUserFormattable = MUserQuotaUsed &
  48. Use<'Account', MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]>> &
  49. PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable>