aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/pod-interface.ts
blob: 8f362bd5cbca8d12100bab4daf8396e8439c5adc (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
64
65
66
67
import * as Sequelize from 'sequelize'

// Don't use barrel, import just what we need
import { Pod as FormatedPod } from '../../shared/models/pod.model'

export namespace PodMethods {
  export type ToFormatedJSON = () => FormatedPod

  export type CountAllCallback = (err: Error, total: number) => void
  export type CountAll = (callback) => void

  export type IncrementScoresCallback = (err: Error) => void
  export type IncrementScores = (ids: number[], value: number, callback?: IncrementScoresCallback) => void

  export type ListCallback = (err: Error, podInstances?: PodInstance[]) => void
  export type List = (callback: ListCallback) => void

  export type ListAllIdsCallback = (err: Error, ids?: number[]) => void
  export type ListAllIds = (transaction: Sequelize.Transaction, callback: ListAllIdsCallback) => void

  export type ListRandomPodIdsWithRequestCallback = (err: Error, podInstanceIds?: number[]) => void
  export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string, callback: ListRandomPodIdsWithRequestCallback) => void

  export type ListBadPodsCallback = (err: Error, podInstances?: PodInstance[]) => void
  export type ListBadPods = (callback: ListBadPodsCallback) => void

  export type LoadCallback = (err: Error, podInstance: PodInstance) => void
  export type Load = (id: number, callback: LoadCallback) => void

  export type LoadByHostCallback = (err: Error, podInstance: PodInstance) => void
  export type LoadByHost = (host: string, callback: LoadByHostCallback) => void

  export type RemoveAllCallback = (err: Error) => void
  export type RemoveAll = (callback: RemoveAllCallback) => void

  export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void
}

export interface PodClass {
  countAll: PodMethods.CountAll
  incrementScores: PodMethods.IncrementScores
  list: PodMethods.List
  listAllIds: PodMethods.ListAllIds
  listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
  listBadPods: PodMethods.ListBadPods
  load: PodMethods.Load
  loadByHost: PodMethods.LoadByHost
  removeAll: PodMethods.RemoveAll
  updatePodsScore: PodMethods.UpdatePodsScore
}

export interface PodAttributes {
  host?: string
  publicKey?: string
  score?: number | Sequelize.literal // Sequelize literal for 'score +' + value
  email?: string
}

export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> {
  id: number
  createdAt: Date
  updatedAt: Date

  toFormatedJSON: PodMethods.ToFormatedJSON,
}

export interface PodModel extends PodClass, Sequelize.Model<PodInstance, PodAttributes> {}