]>
Commit | Line | Data |
---|---|---|
e02643f3 | 1 | import * as Sequelize from 'sequelize' |
69818c93 C |
2 | import * as Bluebird from 'bluebird' |
3 | ||
4 | // Don't use barrel, import just what we need | |
ee9e7b61 | 5 | import { UserRole, User as FormatedUser } from '../../../shared/models/user.model' |
e02643f3 C |
6 | |
7 | export namespace UserMethods { | |
69818c93 | 8 | export type IsPasswordMatchCallback = (err: Error, same: boolean) => void |
70c065d6 | 9 | export type IsPasswordMatch = (this: UserInstance, password: string, callback: IsPasswordMatchCallback) => void |
69818c93 | 10 | |
70c065d6 C |
11 | export type ToFormatedJSON = (this: UserInstance) => FormatedUser |
12 | export type IsAdmin = (this: UserInstance) => boolean | |
e02643f3 | 13 | |
69818c93 C |
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 | |
e02643f3 C |
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 | |
ee9e7b61 | 54 | role: UserRole |
e02643f3 C |
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> {} |