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