2017-05-22 14:58:25 -04:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-07-05 07:26:25 -04:00
|
|
|
import * as Promise from 'bluebird'
|
2017-06-10 16:15:25 -04:00
|
|
|
|
|
|
|
// Don't use barrel, import just what we need
|
2017-08-25 05:45:31 -04:00
|
|
|
import { User as FormattedUser } from '../../../shared/models/users/user.model'
|
2017-07-10 13:43:21 -04:00
|
|
|
import { UserRole } from '../../../shared/models/users/user-role.type'
|
2017-07-05 07:26:25 -04:00
|
|
|
import { ResultList } from '../../../shared/models/result-list.model'
|
2017-10-24 13:41:09 -04:00
|
|
|
import { AuthorInstance } from '../video/author-interface'
|
2017-05-22 14:58:25 -04:00
|
|
|
|
|
|
|
export namespace UserMethods {
|
2017-07-05 07:26:25 -04:00
|
|
|
export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
|
2017-06-10 16:15:25 -04:00
|
|
|
|
2017-08-25 05:45:31 -04:00
|
|
|
export type ToFormattedJSON = (this: UserInstance) => FormattedUser
|
2017-06-16 03:54:59 -04:00
|
|
|
export type IsAdmin = (this: UserInstance) => boolean
|
2017-09-04 14:07:54 -04:00
|
|
|
export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean>
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
export type CountTotal = () => Promise<number>
|
2017-06-10 16:15:25 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
export type GetByUsername = (username: string) => Promise<UserInstance>
|
2017-06-10 16:15:25 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
|
2017-06-10 16:15:25 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
export type LoadById = (id: number) => Promise<UserInstance>
|
2017-06-10 16:15:25 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
export type LoadByUsername = (username: string) => Promise<UserInstance>
|
2017-10-24 13:41:09 -04:00
|
|
|
export type LoadByUsernameAndPopulateChannels = (username: string) => Promise<UserInstance>
|
2017-06-10 16:15:25 -04:00
|
|
|
|
2017-07-05 07:26:25 -04:00
|
|
|
export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
|
2017-05-22 14:58:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserClass {
|
|
|
|
isPasswordMatch: UserMethods.IsPasswordMatch,
|
2017-08-25 05:45:31 -04:00
|
|
|
toFormattedJSON: UserMethods.ToFormattedJSON,
|
2017-05-22 14:58:25 -04:00
|
|
|
isAdmin: UserMethods.IsAdmin,
|
2017-09-04 14:07:54 -04:00
|
|
|
isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo,
|
2017-05-22 14:58:25 -04:00
|
|
|
|
|
|
|
countTotal: UserMethods.CountTotal,
|
|
|
|
getByUsername: UserMethods.GetByUsername,
|
|
|
|
listForApi: UserMethods.ListForApi,
|
|
|
|
loadById: UserMethods.LoadById,
|
|
|
|
loadByUsername: UserMethods.LoadByUsername,
|
2017-10-24 13:41:09 -04:00
|
|
|
loadByUsernameAndPopulateChannels: UserMethods.LoadByUsernameAndPopulateChannels,
|
2017-05-22 14:58:25 -04:00
|
|
|
loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserAttributes {
|
2017-09-04 14:07:54 -04:00
|
|
|
id?: number
|
2017-05-22 14:58:25 -04:00
|
|
|
password: string
|
|
|
|
username: string
|
|
|
|
email: string
|
|
|
|
displayNSFW?: boolean
|
2017-06-16 04:36:18 -04:00
|
|
|
role: UserRole
|
2017-09-04 14:07:54 -04:00
|
|
|
videoQuota: number
|
2017-10-24 13:41:09 -04:00
|
|
|
|
|
|
|
Author?: AuthorInstance
|
2017-05-22 14:58:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
|
|
|
|
id: number
|
|
|
|
createdAt: Date
|
|
|
|
updatedAt: Date
|
2017-06-17 05:28:11 -04:00
|
|
|
|
|
|
|
isPasswordMatch: UserMethods.IsPasswordMatch
|
2017-08-25 05:45:31 -04:00
|
|
|
toFormattedJSON: UserMethods.ToFormattedJSON
|
2017-06-17 05:28:11 -04:00
|
|
|
isAdmin: UserMethods.IsAdmin
|
2017-05-22 14:58:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}
|