Add outbox
[oweals/peertube.git] / server / models / account / user-interface.ts
1 import * as Sequelize from 'sequelize'
2 import * as Bluebird from 'bluebird'
3
4 // Don't use barrel, import just what we need
5 import { AccountInstance } from './account-interface'
6 import { User as FormattedUser } from '../../../shared/models/users/user.model'
7 import { ResultList } from '../../../shared/models/result-list.model'
8 import { UserRight } from '../../../shared/models/users/user-right.enum'
9 import { UserRole } from '../../../shared/models/users/user-role'
10
11 export namespace UserMethods {
12   export type HasRight = (this: UserInstance, right: UserRight) => boolean
13   export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
14
15   export type ToFormattedJSON = (this: UserInstance) => FormattedUser
16   export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean>
17
18   export type CountTotal = () => Bluebird<number>
19
20   export type GetByUsername = (username: string) => Bluebird<UserInstance>
21
22   export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<UserInstance> >
23
24   export type LoadById = (id: number) => Bluebird<UserInstance>
25
26   export type LoadByUsername = (username: string) => Bluebird<UserInstance>
27   export type LoadByUsernameAndPopulateChannels = (username: string) => Bluebird<UserInstance>
28
29   export type LoadByUsernameOrEmail = (username: string, email: string) => Bluebird<UserInstance>
30 }
31
32 export interface UserClass {
33   isPasswordMatch: UserMethods.IsPasswordMatch,
34   toFormattedJSON: UserMethods.ToFormattedJSON,
35   hasRight: UserMethods.HasRight,
36   isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo,
37
38   countTotal: UserMethods.CountTotal,
39   getByUsername: UserMethods.GetByUsername,
40   listForApi: UserMethods.ListForApi,
41   loadById: UserMethods.LoadById,
42   loadByUsername: UserMethods.LoadByUsername,
43   loadByUsernameAndPopulateChannels: UserMethods.LoadByUsernameAndPopulateChannels,
44   loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
45 }
46
47 export interface UserAttributes {
48   id?: number
49   password: string
50   username: string
51   email: string
52   displayNSFW?: boolean
53   role: UserRole
54   videoQuota: number
55
56   Account?: AccountInstance
57 }
58
59 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
60   id: number
61   createdAt: Date
62   updatedAt: Date
63
64   isPasswordMatch: UserMethods.IsPasswordMatch
65   toFormattedJSON: UserMethods.ToFormattedJSON
66   hasRight: UserMethods.HasRight
67 }
68
69 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}