1
0
Fork 0
peertube/server/models/pod/pod-interface.ts

60 lines
1.9 KiB
TypeScript
Raw Normal View History

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