]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/user/user-interface.ts
1ba4bd800d5e6bd44c0280ecea4b63cddacdb948
[github/Chocobozzz/PeerTube.git] / server / models / user / user-interface.ts
1 import * as Sequelize from 'sequelize'
2 import * as Bluebird from 'bluebird'
3
4 // Don't use barrel, import just what we need
5 import { User as FormatedUser } from '../../../shared/models/user.model'
6
7 export namespace UserMethods {
8 export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
9 export type IsPasswordMatch = (password: string, callback: IsPasswordMatchCallback) => void
10
11 export type ToFormatedJSON = () => FormatedUser
12 export type IsAdmin = () => boolean
13
14 export type CountTotalCallback = (err: Error, total: number) => void
15 export type CountTotal = (callback: CountTotalCallback) => void
16
17 export type GetByUsername = (username: string) => Bluebird<UserInstance>
18
19 export type ListCallback = (err: Error, userInstances: UserInstance[]) => void
20 export type List = (callback: ListCallback) => void
21
22 export type ListForApiCallback = (err: Error, userInstances?: UserInstance[], total?: number) => void
23 export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
24
25 export type LoadByIdCallback = (err: Error, userInstance: UserInstance) => void
26 export type LoadById = (id: number, callback: LoadByIdCallback) => void
27
28 export type LoadByUsernameCallback = (err: Error, userInstance: UserInstance) => void
29 export type LoadByUsername = (username: string, callback: LoadByUsernameCallback) => void
30
31 export type LoadByUsernameOrEmailCallback = (err: Error, userInstance: UserInstance) => void
32 export type LoadByUsernameOrEmail = (username: string, email: string, callback: LoadByUsernameOrEmailCallback) => void
33 }
34
35 export interface UserClass {
36 isPasswordMatch: UserMethods.IsPasswordMatch,
37 toFormatedJSON: UserMethods.ToFormatedJSON,
38 isAdmin: UserMethods.IsAdmin,
39
40 countTotal: UserMethods.CountTotal,
41 getByUsername: UserMethods.GetByUsername,
42 list: UserMethods.List,
43 listForApi: UserMethods.ListForApi,
44 loadById: UserMethods.LoadById,
45 loadByUsername: UserMethods.LoadByUsername,
46 loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
47 }
48
49 export interface UserAttributes {
50 password: string
51 username: string
52 email: string
53 displayNSFW?: boolean
54 role: string
55 }
56
57 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
58 id: number
59 createdAt: Date
60 updatedAt: Date
61 }
62
63 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}