2017-11-09 10:51:58 -06:00
|
|
|
import * as Bluebird from 'bluebird'
|
2017-11-30 03:51:13 -06:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-07-05 06:26:25 -05:00
|
|
|
import { ResultList } from '../../../shared/models/result-list.model'
|
2017-10-27 09:55:03 -05:00
|
|
|
import { UserRight } from '../../../shared/models/users/user-right.enum'
|
|
|
|
import { UserRole } from '../../../shared/models/users/user-role'
|
2017-11-30 03:51:13 -06:00
|
|
|
import { User as FormattedUser } from '../../../shared/models/users/user.model'
|
|
|
|
import { AccountInstance } from './account-interface'
|
2017-05-22 13:58:25 -05:00
|
|
|
|
|
|
|
export namespace UserMethods {
|
2017-10-27 09:55:03 -05:00
|
|
|
export type HasRight = (this: UserInstance, right: UserRight) => boolean
|
2017-07-05 06:26:25 -05:00
|
|
|
export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-08-25 04:45:31 -05:00
|
|
|
export type ToFormattedJSON = (this: UserInstance) => FormattedUser
|
2017-09-04 13:07:54 -05:00
|
|
|
export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean>
|
2017-05-22 13:58:25 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export type CountTotal = () => Bluebird<number>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export type GetByUsername = (username: string) => Bluebird<UserInstance>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<UserInstance> >
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export type LoadById = (id: number) => Bluebird<UserInstance>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export type LoadByUsername = (username: string) => Bluebird<UserInstance>
|
|
|
|
export type LoadByUsernameAndPopulateChannels = (username: string) => Bluebird<UserInstance>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
export type LoadByUsernameOrEmail = (username: string, email: string) => Bluebird<UserInstance>
|
2017-05-22 13:58:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserClass {
|
|
|
|
isPasswordMatch: UserMethods.IsPasswordMatch,
|
2017-08-25 04:45:31 -05:00
|
|
|
toFormattedJSON: UserMethods.ToFormattedJSON,
|
2017-10-27 09:55:03 -05:00
|
|
|
hasRight: UserMethods.HasRight,
|
2017-09-04 13:07:54 -05:00
|
|
|
isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo,
|
2017-05-22 13:58:25 -05:00
|
|
|
|
|
|
|
countTotal: UserMethods.CountTotal,
|
|
|
|
getByUsername: UserMethods.GetByUsername,
|
|
|
|
listForApi: UserMethods.ListForApi,
|
|
|
|
loadById: UserMethods.LoadById,
|
|
|
|
loadByUsername: UserMethods.LoadByUsername,
|
2017-10-24 12:41:09 -05:00
|
|
|
loadByUsernameAndPopulateChannels: UserMethods.LoadByUsernameAndPopulateChannels,
|
2017-05-22 13:58:25 -05:00
|
|
|
loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserAttributes {
|
2017-09-04 13:07:54 -05:00
|
|
|
id?: number
|
2017-05-22 13:58:25 -05:00
|
|
|
password: string
|
|
|
|
username: string
|
|
|
|
email: string
|
|
|
|
displayNSFW?: boolean
|
2017-06-16 03:36:18 -05:00
|
|
|
role: UserRole
|
2017-09-04 13:07:54 -05:00
|
|
|
videoQuota: number
|
2017-10-24 12:41:09 -05:00
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
Account?: AccountInstance
|
2017-05-22 13:58:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
|
|
|
|
id: number
|
|
|
|
createdAt: Date
|
|
|
|
updatedAt: Date
|
2017-06-17 04:28:11 -05:00
|
|
|
|
|
|
|
isPasswordMatch: UserMethods.IsPasswordMatch
|
2017-08-25 04:45:31 -05:00
|
|
|
toFormattedJSON: UserMethods.ToFormattedJSON
|
2017-10-27 09:55:03 -05:00
|
|
|
hasRight: UserMethods.HasRight
|
2017-05-22 13:58:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}
|