]>
Commit | Line | Data |
---|---|---|
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 FormattedUser } 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 ToFormattedJSON = (this: UserInstance) => FormattedUser | |
13 | export type IsAdmin = (this: UserInstance) => boolean | |
14 | export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean> | |
15 | ||
16 | export type CountTotal = () => Promise<number> | |
17 | ||
18 | export type GetByUsername = (username: string) => Promise<UserInstance> | |
19 | ||
20 | export type List = () => Promise<UserInstance[]> | |
21 | ||
22 | export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> > | |
23 | ||
24 | export type LoadById = (id: number) => Promise<UserInstance> | |
25 | ||
26 | export type LoadByUsername = (username: string) => Promise<UserInstance> | |
27 | ||
28 | export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance> | |
29 | } | |
30 | ||
31 | export interface UserClass { | |
32 | isPasswordMatch: UserMethods.IsPasswordMatch, | |
33 | toFormattedJSON: UserMethods.ToFormattedJSON, | |
34 | isAdmin: UserMethods.IsAdmin, | |
35 | isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo, | |
36 | ||
37 | countTotal: UserMethods.CountTotal, | |
38 | getByUsername: UserMethods.GetByUsername, | |
39 | list: UserMethods.List, | |
40 | listForApi: UserMethods.ListForApi, | |
41 | loadById: UserMethods.LoadById, | |
42 | loadByUsername: UserMethods.LoadByUsername, | |
43 | loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail | |
44 | } | |
45 | ||
46 | export interface UserAttributes { | |
47 | id?: number | |
48 | password: string | |
49 | username: string | |
50 | email: string | |
51 | displayNSFW?: boolean | |
52 | role: UserRole | |
53 | videoQuota: number | |
54 | } | |
55 | ||
56 | export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> { | |
57 | id: number | |
58 | createdAt: Date | |
59 | updatedAt: Date | |
60 | ||
61 | isPasswordMatch: UserMethods.IsPasswordMatch | |
62 | toFormattedJSON: UserMethods.ToFormattedJSON | |
63 | isAdmin: UserMethods.IsAdmin | |
64 | } | |
65 | ||
66 | export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {} |