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