2017-05-22 13:58:25 -05:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-07-05 06:26:25 -05:00
|
|
|
import * as Promise from 'bluebird'
|
2017-05-22 13:58:25 -05:00
|
|
|
|
2017-06-10 15:15:25 -05:00
|
|
|
// Don't use barrel, import just what we need
|
2017-07-10 12:43:21 -05:00
|
|
|
import { Pod as FormatedPod } from '../../../shared/models/pods/pod.model'
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-05-22 13:58:25 -05:00
|
|
|
export namespace PodMethods {
|
2017-06-16 02:54:59 -05:00
|
|
|
export type ToFormatedJSON = (this: PodInstance) => FormatedPod
|
2017-05-22 13:58:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type CountAll = () => Promise<number>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type List = () => Promise<PodInstance[]>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise<number[]>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type ListBadPods = () => Promise<PodInstance[]>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type Load = (id: number) => Promise<PodInstance>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type LoadByHost = (host: string) => Promise<PodInstance>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
2017-07-05 06:26:25 -05:00
|
|
|
export type RemoveAll = () => Promise<number>
|
2017-06-10 15:15:25 -05:00
|
|
|
|
|
|
|
export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void
|
2017-05-22 13:58:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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> {}
|