aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/pod/pod-interface.ts
blob: 340d4f1a784cbe0791cdfbc1a364891940147b05 (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
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'

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

export namespace PodMethods {
  export type ToFormatedJSON = (this: PodInstance) => FormatedPod

  export type CountAll = () => Promise<number>

  export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]>

  export type List = () => Promise<PodInstance[]>

  export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>

  export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise<number[]>

  export type ListBadPods = () => Promise<PodInstance[]>

  export type Load = (id: number) => Promise<PodInstance>

  export type LoadByHost = (host: string) => Promise<PodInstance>

  export type RemoveAll = () => Promise<number>

  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> {}