aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user/user-interface.ts
blob: 1ba4bd800d5e6bd44c0280ecea4b63cddacdb948 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as Sequelize from 'sequelize'
import * as Bluebird from 'bluebird'

// Don't use barrel, import just what we need
import { User as FormatedUser } from '../../../shared/models/user.model'

export namespace UserMethods {
  export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
  export type IsPasswordMatch = (password: string, callback: IsPasswordMatchCallback) => void

  export type ToFormatedJSON = () => FormatedUser
  export type IsAdmin = () => boolean

  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
}

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
  role: string
}

export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
  id: number
  createdAt: Date
  updatedAt: Date
}

export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}