import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' // Don't use barrel, import just what we need import { User as FormattedUser } from '../../../shared/models/users/user.model' import { UserRole } from '../../../shared/models/users/user-role.type' import { ResultList } from '../../../shared/models/result-list.model' export namespace UserMethods { export type IsPasswordMatch = (this: UserInstance, password: string) => Promise export type ToFormattedJSON = (this: UserInstance) => FormattedUser export type IsAdmin = (this: UserInstance) => boolean export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise export type CountTotal = () => Promise export type GetByUsername = (username: string) => Promise export type List = () => Promise export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList > export type LoadById = (id: number) => Promise export type LoadByUsername = (username: string) => Promise export type LoadByUsernameOrEmail = (username: string, email: string) => Promise } export interface UserClass { isPasswordMatch: UserMethods.IsPasswordMatch, toFormattedJSON: UserMethods.ToFormattedJSON, isAdmin: UserMethods.IsAdmin, isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo, countTotal: UserMethods.CountTotal, getByUsername: UserMethods.GetByUsername, list: UserMethods.List, listForApi: UserMethods.ListForApi, loadById: UserMethods.LoadById, loadByUsername: UserMethods.LoadByUsername, loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail } export interface UserAttributes { id?: number password: string username: string email: string displayNSFW?: boolean role: UserRole videoQuota: number } export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance { id: number createdAt: Date updatedAt: Date isPasswordMatch: UserMethods.IsPasswordMatch toFormattedJSON: UserMethods.ToFormattedJSON isAdmin: UserMethods.IsAdmin } export interface UserModel extends UserClass, Sequelize.Model {}