]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/user/user-interface.ts
Formated -> Formatted
[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
e02643f3 14
6fcd19ba 15 export type CountTotal = () => Promise<number>
69818c93 16
6fcd19ba 17 export type GetByUsername = (username: string) => Promise<UserInstance>
69818c93 18
6fcd19ba 19 export type List = () => Promise<UserInstance[]>
69818c93 20
6fcd19ba 21 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
69818c93 22
6fcd19ba 23 export type LoadById = (id: number) => Promise<UserInstance>
69818c93 24
6fcd19ba 25 export type LoadByUsername = (username: string) => Promise<UserInstance>
69818c93 26
6fcd19ba 27 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
e02643f3
C
28}
29
30export interface UserClass {
31 isPasswordMatch: UserMethods.IsPasswordMatch,
0aef76c4 32 toFormattedJSON: UserMethods.ToFormattedJSON,
e02643f3
C
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
44export interface UserAttributes {
45 password: string
46 username: string
47 email: string
48 displayNSFW?: boolean
ee9e7b61 49 role: UserRole
e02643f3
C
50}
51
52export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
53 id: number
54 createdAt: Date
55 updatedAt: Date
154898b0
C
56
57 isPasswordMatch: UserMethods.IsPasswordMatch
0aef76c4 58 toFormattedJSON: UserMethods.ToFormattedJSON
154898b0 59 isAdmin: UserMethods.IsAdmin
e02643f3
C
60}
61
62export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}