]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/user/user-interface.ts
Fix spelling (#126)
[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 { ResultList } from '../../../shared/models/result-list.model'
7 import { AuthorInstance } from '../video/author-interface'
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 = () => Promise<number>
19
20 export type GetByUsername = (username: string) => Promise<UserInstance>
21
22 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
23
24 export type LoadById = (id: number) => Promise<UserInstance>
25
26 export type LoadByUsername = (username: string) => Promise<UserInstance>
27 export type LoadByUsernameAndPopulateChannels = (username: string) => Promise<UserInstance>
28
29 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<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 Author?: AuthorInstance
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> {}