]>
Commit | Line | Data |
---|---|---|
e02643f3 | 1 | import * as Sequelize from 'sequelize' |
6fcd19ba | 2 | import * as Promise from 'bluebird' |
69818c93 C |
3 | |
4 | // Don't use barrel, import just what we need | |
ee9e7b61 | 5 | import { UserRole, User as FormatedUser } from '../../../shared/models/user.model' |
6fcd19ba | 6 | import { ResultList } from '../../../shared/models/result-list.model' |
e02643f3 C |
7 | |
8 | export namespace UserMethods { | |
6fcd19ba | 9 | export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean> |
69818c93 | 10 | |
70c065d6 C |
11 | export type ToFormatedJSON = (this: UserInstance) => FormatedUser |
12 | export type IsAdmin = (this: UserInstance) => boolean | |
e02643f3 | 13 | |
6fcd19ba | 14 | export type CountTotal = () => Promise<number> |
69818c93 | 15 | |
6fcd19ba | 16 | export type GetByUsername = (username: string) => Promise<UserInstance> |
69818c93 | 17 | |
6fcd19ba | 18 | export type List = () => Promise<UserInstance[]> |
69818c93 | 19 | |
6fcd19ba | 20 | export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> > |
69818c93 | 21 | |
6fcd19ba | 22 | export type LoadById = (id: number) => Promise<UserInstance> |
69818c93 | 23 | |
6fcd19ba | 24 | export type LoadByUsername = (username: string) => Promise<UserInstance> |
69818c93 | 25 | |
6fcd19ba | 26 | export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance> |
e02643f3 C |
27 | } |
28 | ||
29 | export interface UserClass { | |
30 | isPasswordMatch: UserMethods.IsPasswordMatch, | |
31 | toFormatedJSON: UserMethods.ToFormatedJSON, | |
32 | isAdmin: UserMethods.IsAdmin, | |
33 | ||
34 | countTotal: UserMethods.CountTotal, | |
35 | getByUsername: UserMethods.GetByUsername, | |
36 | list: UserMethods.List, | |
37 | listForApi: UserMethods.ListForApi, | |
38 | loadById: UserMethods.LoadById, | |
39 | loadByUsername: UserMethods.LoadByUsername, | |
40 | loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail | |
41 | } | |
42 | ||
43 | export interface UserAttributes { | |
44 | password: string | |
45 | username: string | |
46 | email: string | |
47 | displayNSFW?: boolean | |
ee9e7b61 | 48 | role: UserRole |
e02643f3 C |
49 | } |
50 | ||
51 | export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> { | |
52 | id: number | |
53 | createdAt: Date | |
54 | updatedAt: Date | |
154898b0 C |
55 | |
56 | isPasswordMatch: UserMethods.IsPasswordMatch | |
57 | toFormatedJSON: UserMethods.ToFormatedJSON | |
58 | isAdmin: UserMethods.IsAdmin | |
e02643f3 C |
59 | } |
60 | ||
61 | export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {} |