2017-05-22 20:58:25 +02:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-07-05 13:26:25 +02:00
|
|
|
import * as Promise from 'bluebird'
|
2017-06-10 22:15:25 +02:00
|
|
|
|
|
|
|
// Don't use barrel, import just what we need
|
2017-07-10 19:43:21 +02:00
|
|
|
import { User as FormatedUser } from '../../../shared/models/users/user.model'
|
|
|
|
import { UserRole } from '../../../shared/models/users/user-role.type'
|
2017-07-05 13:26:25 +02:00
|
|
|
import { ResultList } from '../../../shared/models/result-list.model'
|
2017-05-22 20:58:25 +02:00
|
|
|
|
|
|
|
export namespace UserMethods {
|
2017-07-05 13:26:25 +02:00
|
|
|
export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
|
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-07-05 13:26:25 +02:00
|
|
|
export type CountTotal = () => Promise<number>
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type GetByUsername = (username: string) => Promise<UserInstance>
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type List = () => Promise<UserInstance[]>
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type LoadById = (id: number) => Promise<UserInstance>
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type LoadByUsername = (username: string) => Promise<UserInstance>
|
2017-06-10 22:15:25 +02:00
|
|
|
|
2017-07-05 13:26:25 +02:00
|
|
|
export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
|
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> {}
|