]>
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 | |
4771e000 C |
5 | import { User as FormatedUser } from '../../../shared/models/users/user.model' |
6 | import { UserRole } from '../../../shared/models/users/user-role.type' | |
6fcd19ba | 7 | import { ResultList } from '../../../shared/models/result-list.model' |
e02643f3 C |
8 | |
9 | export namespace UserMethods { | |
6fcd19ba | 10 | export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean> |
69818c93 | 11 | |
70c065d6 C |
12 | export type ToFormatedJSON = (this: UserInstance) => FormatedUser |
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 | ||
30 | export interface UserClass { | |
31 | isPasswordMatch: UserMethods.IsPasswordMatch, | |
32 | toFormatedJSON: UserMethods.ToFormatedJSON, | |
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 | ||
44 | export interface UserAttributes { | |
45 | password: string | |
46 | username: string | |
47 | email: string | |
48 | displayNSFW?: boolean | |
ee9e7b61 | 49 | role: UserRole |
e02643f3 C |
50 | } |
51 | ||
52 | export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> { | |
53 | id: number | |
54 | createdAt: Date | |
55 | updatedAt: Date | |
154898b0 C |
56 | |
57 | isPasswordMatch: UserMethods.IsPasswordMatch | |
58 | toFormatedJSON: UserMethods.ToFormatedJSON | |
59 | isAdmin: UserMethods.IsAdmin | |
e02643f3 C |
60 | } |
61 | ||
62 | export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {} |