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