1 import * as Sequelize from 'sequelize'
2 import * as Bluebird from 'bluebird'
4 // Don't use barrel, import just what we need
5 import { User as FormatedUser } from '../../shared/models/user.model'
7 export namespace UserMethods {
8 export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
9 export type IsPasswordMatch = (password: string, callback: IsPasswordMatchCallback) => void
11 export type ToFormatedJSON = () => FormatedUser
12 export type IsAdmin = () => boolean
14 export type CountTotalCallback = (err: Error, total: number) => void
15 export type CountTotal = (callback: CountTotalCallback) => void
17 export type GetByUsername = (username: string) => Bluebird<UserInstance>
19 export type ListCallback = (err: Error, userInstances: UserInstance[]) => void
20 export type List = (callback: ListCallback) => void
22 export type ListForApiCallback = (err: Error, userInstances?: UserInstance[], total?: number) => void
23 export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
25 export type LoadByIdCallback = (err: Error, userInstance: UserInstance) => void
26 export type LoadById = (id: number, callback: LoadByIdCallback) => void
28 export type LoadByUsernameCallback = (err: Error, userInstance: UserInstance) => void
29 export type LoadByUsername = (username: string, callback: LoadByUsernameCallback) => void
31 export type LoadByUsernameOrEmailCallback = (err: Error, userInstance: UserInstance) => void
32 export type LoadByUsernameOrEmail = (username: string, email: string, callback: LoadByUsernameOrEmailCallback) => void
35 export interface UserClass {
36 isPasswordMatch: UserMethods.IsPasswordMatch,
37 toFormatedJSON: UserMethods.ToFormatedJSON,
38 isAdmin: UserMethods.IsAdmin,
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
49 export interface UserAttributes {
57 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
63 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}