1 import * as Sequelize from 'sequelize'
2 import * as Promise from 'bluebird'
4 // Don't use barrel, import just what we need
5 import { UserRole, User as FormatedUser } from '../../../shared/models/user.model'
6 import { ResultList } from '../../../shared/models/result-list.model'
8 export namespace UserMethods {
9 export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
11 export type ToFormatedJSON = (this: UserInstance) => FormatedUser
12 export type IsAdmin = (this: UserInstance) => boolean
14 export type CountTotal = () => Promise<number>
16 export type GetByUsername = (username: string) => Promise<UserInstance>
18 export type List = () => Promise<UserInstance[]>
20 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
22 export type LoadById = (id: number) => Promise<UserInstance>
24 export type LoadByUsername = (username: string) => Promise<UserInstance>
26 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
29 export interface UserClass {
30 isPasswordMatch: UserMethods.IsPasswordMatch,
31 toFormatedJSON: UserMethods.ToFormatedJSON,
32 isAdmin: UserMethods.IsAdmin,
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
43 export interface UserAttributes {
51 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
56 isPasswordMatch: UserMethods.IsPasswordMatch
57 toFormatedJSON: UserMethods.ToFormatedJSON
58 isAdmin: UserMethods.IsAdmin
61 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}