]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/user/user-interface.ts
Upgrade express validator to v4
[github/Chocobozzz/PeerTube.git] / server / models / user / user-interface.ts
CommitLineData
e02643f3 1import * as Sequelize from 'sequelize'
6fcd19ba 2import * as Promise from 'bluebird'
69818c93
C
3
4// Don't use barrel, import just what we need
0aef76c4 5import { User as FormattedUser } from '../../../shared/models/users/user.model'
4771e000 6import { UserRole } from '../../../shared/models/users/user-role.type'
6fcd19ba 7import { ResultList } from '../../../shared/models/result-list.model'
e02643f3
C
8
9export namespace UserMethods {
6fcd19ba 10 export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
69818c93 11
0aef76c4 12 export type ToFormattedJSON = (this: UserInstance) => FormattedUser
70c065d6 13 export type IsAdmin = (this: UserInstance) => boolean
b0f9f39e 14 export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean>
e02643f3 15
6fcd19ba 16 export type CountTotal = () => Promise<number>
69818c93 17
6fcd19ba 18 export type GetByUsername = (username: string) => Promise<UserInstance>
69818c93 19
6fcd19ba 20 export type List = () => Promise<UserInstance[]>
69818c93 21
6fcd19ba 22 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
69818c93 23
6fcd19ba 24 export type LoadById = (id: number) => Promise<UserInstance>
69818c93 25
6fcd19ba 26 export type LoadByUsername = (username: string) => Promise<UserInstance>
69818c93 27
6fcd19ba 28 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
e02643f3
C
29}
30
31export interface UserClass {
32 isPasswordMatch: UserMethods.IsPasswordMatch,
0aef76c4 33 toFormattedJSON: UserMethods.ToFormattedJSON,
e02643f3 34 isAdmin: UserMethods.IsAdmin,
b0f9f39e 35 isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo,
e02643f3
C
36
37 countTotal: UserMethods.CountTotal,
38 getByUsername: UserMethods.GetByUsername,
39 list: UserMethods.List,
40 listForApi: UserMethods.ListForApi,
41 loadById: UserMethods.LoadById,
42 loadByUsername: UserMethods.LoadByUsername,
43 loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
44}
45
46export interface UserAttributes {
b0f9f39e 47 id?: number
e02643f3
C
48 password: string
49 username: string
50 email: string
51 displayNSFW?: boolean
ee9e7b61 52 role: UserRole
b0f9f39e 53 videoQuota: number
e02643f3
C
54}
55
56export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
57 id: number
58 createdAt: Date
59 updatedAt: Date
154898b0
C
60
61 isPasswordMatch: UserMethods.IsPasswordMatch
0aef76c4 62 toFormattedJSON: UserMethods.ToFormattedJSON
154898b0 63 isAdmin: UserMethods.IsAdmin
e02643f3
C
64}
65
66export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}