]>
Commit | Line | Data |
---|---|---|
e02643f3 | 1 | import * as Sequelize from 'sequelize' |
e4f97bab | 2 | import * as Bluebird from 'bluebird' |
69818c93 C |
3 | |
4 | // Don't use barrel, import just what we need | |
e4f97bab | 5 | import { AccountInstance } from './account-interface' |
0aef76c4 | 6 | import { User as FormattedUser } from '../../../shared/models/users/user.model' |
6fcd19ba | 7 | import { ResultList } from '../../../shared/models/result-list.model' |
954605a8 C |
8 | import { UserRight } from '../../../shared/models/users/user-right.enum' |
9 | import { UserRole } from '../../../shared/models/users/user-role' | |
e02643f3 C |
10 | |
11 | export namespace UserMethods { | |
954605a8 | 12 | export type HasRight = (this: UserInstance, right: UserRight) => boolean |
6fcd19ba | 13 | export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean> |
69818c93 | 14 | |
0aef76c4 | 15 | export type ToFormattedJSON = (this: UserInstance) => FormattedUser |
b0f9f39e | 16 | export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean> |
e02643f3 | 17 | |
e4f97bab | 18 | export type CountTotal = () => Bluebird<number> |
69818c93 | 19 | |
e4f97bab | 20 | export type GetByUsername = (username: string) => Bluebird<UserInstance> |
69818c93 | 21 | |
e4f97bab | 22 | export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<UserInstance> > |
69818c93 | 23 | |
e4f97bab | 24 | export type LoadById = (id: number) => Bluebird<UserInstance> |
69818c93 | 25 | |
e4f97bab C |
26 | export type LoadByUsername = (username: string) => Bluebird<UserInstance> |
27 | export type LoadByUsernameAndPopulateChannels = (username: string) => Bluebird<UserInstance> | |
69818c93 | 28 | |
e4f97bab | 29 | export type LoadByUsernameOrEmail = (username: string, email: string) => Bluebird<UserInstance> |
e02643f3 C |
30 | } |
31 | ||
32 | export interface UserClass { | |
33 | isPasswordMatch: UserMethods.IsPasswordMatch, | |
0aef76c4 | 34 | toFormattedJSON: UserMethods.ToFormattedJSON, |
954605a8 | 35 | hasRight: UserMethods.HasRight, |
b0f9f39e | 36 | isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo, |
e02643f3 C |
37 | |
38 | countTotal: UserMethods.CountTotal, | |
39 | getByUsername: UserMethods.GetByUsername, | |
e02643f3 C |
40 | listForApi: UserMethods.ListForApi, |
41 | loadById: UserMethods.LoadById, | |
42 | loadByUsername: UserMethods.LoadByUsername, | |
72c7248b | 43 | loadByUsernameAndPopulateChannels: UserMethods.LoadByUsernameAndPopulateChannels, |
e02643f3 C |
44 | loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail |
45 | } | |
46 | ||
47 | export interface UserAttributes { | |
b0f9f39e | 48 | id?: number |
e02643f3 C |
49 | password: string |
50 | username: string | |
51 | email: string | |
52 | displayNSFW?: boolean | |
ee9e7b61 | 53 | role: UserRole |
b0f9f39e | 54 | videoQuota: number |
72c7248b | 55 | |
e4f97bab | 56 | Account?: AccountInstance |
e02643f3 C |
57 | } |
58 | ||
59 | export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> { | |
60 | id: number | |
61 | createdAt: Date | |
62 | updatedAt: Date | |
154898b0 C |
63 | |
64 | isPasswordMatch: UserMethods.IsPasswordMatch | |
0aef76c4 | 65 | toFormattedJSON: UserMethods.ToFormattedJSON |
954605a8 | 66 | hasRight: UserMethods.HasRight |
e02643f3 C |
67 | } |
68 | ||
69 | export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {} |