1 import * as Sequelize from 'sequelize'
2 import * as Promise from 'bluebird'
4 // Don't use barrel, import just what we need
5 import { User as FormatedUser } 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'
9 export namespace UserMethods {
10 export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
12 export type ToFormatedJSON = (this: UserInstance) => FormatedUser
13 export type IsAdmin = (this: UserInstance) => boolean
15 export type CountTotal = () => Promise<number>
17 export type GetByUsername = (username: string) => Promise<UserInstance>
19 export type List = () => Promise<UserInstance[]>
21 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
23 export type LoadById = (id: number) => Promise<UserInstance>
25 export type LoadByUsername = (username: string) => Promise<UserInstance>
27 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
30 export interface UserClass {
31 isPasswordMatch: UserMethods.IsPasswordMatch,
32 toFormatedJSON: UserMethods.ToFormatedJSON,
33 isAdmin: UserMethods.IsAdmin,
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
44 export interface UserAttributes {
52 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
57 isPasswordMatch: UserMethods.IsPasswordMatch
58 toFormatedJSON: UserMethods.ToFormatedJSON
59 isAdmin: UserMethods.IsAdmin
62 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}