2017-05-22 20:58:25 +02:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-06-10 22:15:25 +02:00
|
|
|
import * as Bluebird from 'bluebird'
|
|
|
|
|
|
|
|
// Don't use barrel, import just what we need
|
2017-06-16 10:36:18 +02:00
|
|
|
import { UserRole, User as FormatedUser } from '../../../shared/models/user.model'
|
2017-05-22 20:58:25 +02:00
|
|
|
|
|
|
|
export namespace UserMethods {
|
2017-06-10 22:15:25 +02:00
|
|
|
export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
|
2017-06-16 09:54:59 +02:00
|
|
|
export type IsPasswordMatch = (this: UserInstance, password: string, callback: IsPasswordMatchCallback) => void
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-06-16 09:54:59 +02:00
|
|
|
export type ToFormatedJSON = (this: UserInstance) => FormatedUser
|
|
|
|
export type IsAdmin = (this: UserInstance) => boolean
|
2017-05-22 20:58:25 +02:00
|
|
|
|
2017-06-10 22:15:25 +02:00
|
|
|
export type CountTotalCallback = (err: Error, total: number) => void
|
|
|
|
export type CountTotal = (callback: CountTotalCallback) => void
|
|
|
|
|
|
|
|
export type GetByUsername = (username: string) => Bluebird<UserInstance>
|
|
|
|
|
|
|
|
export type ListCallback = (err: Error, userInstances: UserInstance[]) => void
|
|
|
|
export type List = (callback: ListCallback) => void
|
|
|
|
|
|
|
|
export type ListForApiCallback = (err: Error, userInstances?: UserInstance[], total?: number) => void
|
|
|
|
export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
|
|
|
|
|
|
|
|
export type LoadByIdCallback = (err: Error, userInstance: UserInstance) => void
|
|
|
|
export type LoadById = (id: number, callback: LoadByIdCallback) => void
|
|
|
|
|
|
|
|
export type LoadByUsernameCallback = (err: Error, userInstance: UserInstance) => void
|
|
|
|
export type LoadByUsername = (username: string, callback: LoadByUsernameCallback) => void
|
|
|
|
|
|
|
|
export type LoadByUsernameOrEmailCallback = (err: Error, userInstance: UserInstance) => void
|
|
|
|
export type LoadByUsernameOrEmail = (username: string, email: string, callback: LoadByUsernameOrEmailCallback) => void
|
2017-05-22 20:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserClass {
|
|
|
|
isPasswordMatch: UserMethods.IsPasswordMatch,
|
|
|
|
toFormatedJSON: UserMethods.ToFormatedJSON,
|
|
|
|
isAdmin: UserMethods.IsAdmin,
|
|
|
|
|
|
|
|
countTotal: UserMethods.CountTotal,
|
|
|
|
getByUsername: UserMethods.GetByUsername,
|
|
|
|
list: UserMethods.List,
|
|
|
|
listForApi: UserMethods.ListForApi,
|
|
|
|
loadById: UserMethods.LoadById,
|
|
|
|
loadByUsername: UserMethods.LoadByUsername,
|
|
|
|
loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserAttributes {
|
|
|
|
password: string
|
|
|
|
username: string
|
|
|
|
email: string
|
|
|
|
displayNSFW?: boolean
|
2017-06-16 10:36:18 +02:00
|
|
|
role: UserRole
|
2017-05-22 20:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
|
|
|
|
id: number
|
|
|
|
createdAt: Date
|
|
|
|
updatedAt: Date
|
2017-06-17 11:28:11 +02:00
|
|
|
|
|
|
|
isPasswordMatch: UserMethods.IsPasswordMatch
|
|
|
|
toFormatedJSON: UserMethods.ToFormatedJSON
|
|
|
|
isAdmin: UserMethods.IsAdmin
|
2017-05-22 20:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}
|