]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/user/user-interface.ts
f743945f83e798fee385dd4f2690c11d4c3c68cf
[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 { UserRole, User as FormatedUser } from '../../../shared/models/user.model'
6 import { ResultList } from '../../../shared/models/result-list.model'
7
8 export namespace UserMethods {
9 export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
10
11 export type ToFormatedJSON = (this: UserInstance) => FormatedUser
12 export type IsAdmin = (this: UserInstance) => boolean
13
14 export type CountTotal = () => Promise<number>
15
16 export type GetByUsername = (username: string) => Promise<UserInstance>
17
18 export type List = () => Promise<UserInstance[]>
19
20 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
21
22 export type LoadById = (id: number) => Promise<UserInstance>
23
24 export type LoadByUsername = (username: string) => Promise<UserInstance>
25
26 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
27 }
28
29 export interface UserClass {
30 isPasswordMatch: UserMethods.IsPasswordMatch,
31 toFormatedJSON: UserMethods.ToFormatedJSON,
32 isAdmin: UserMethods.IsAdmin,
33
34 countTotal: UserMethods.CountTotal,
35 getByUsername: UserMethods.GetByUsername,
36 list: UserMethods.List,
37 listForApi: UserMethods.ListForApi,
38 loadById: UserMethods.LoadById,
39 loadByUsername: UserMethods.LoadByUsername,
40 loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
41 }
42
43 export interface UserAttributes {
44 password: string
45 username: string
46 email: string
47 displayNSFW?: boolean
48 role: UserRole
49 }
50
51 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
52 id: number
53 createdAt: Date
54 updatedAt: Date
55
56 isPasswordMatch: UserMethods.IsPasswordMatch
57 toFormatedJSON: UserMethods.ToFormatedJSON
58 isAdmin: UserMethods.IsAdmin
59 }
60
61 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}