]>
Commit | Line | Data |
---|---|---|
e02643f3 | 1 | import * as Sequelize from 'sequelize' |
6fcd19ba | 2 | import * as Promise from 'bluebird' |
e02643f3 | 3 | |
69818c93 | 4 | // Don't use barrel, import just what we need |
4771e000 | 5 | import { Pod as FormatedPod } from '../../../shared/models/pods/pod.model' |
69818c93 | 6 | |
e02643f3 | 7 | export namespace PodMethods { |
70c065d6 | 8 | export type ToFormatedJSON = (this: PodInstance) => FormatedPod |
e02643f3 | 9 | |
6fcd19ba | 10 | export type CountAll = () => Promise<number> |
69818c93 | 11 | |
6fcd19ba | 12 | export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]> |
69818c93 | 13 | |
6fcd19ba | 14 | export type List = () => Promise<PodInstance[]> |
69818c93 | 15 | |
6fcd19ba | 16 | export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]> |
69818c93 | 17 | |
6fcd19ba | 18 | export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise<number[]> |
69818c93 | 19 | |
6fcd19ba | 20 | export type ListBadPods = () => Promise<PodInstance[]> |
69818c93 | 21 | |
6fcd19ba | 22 | export type Load = (id: number) => Promise<PodInstance> |
69818c93 | 23 | |
6fcd19ba | 24 | export type LoadByHost = (host: string) => Promise<PodInstance> |
69818c93 | 25 | |
6fcd19ba | 26 | export type RemoveAll = () => Promise<number> |
69818c93 C |
27 | |
28 | export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void | |
e02643f3 C |
29 | } |
30 | ||
31 | export interface PodClass { | |
32 | countAll: PodMethods.CountAll | |
33 | incrementScores: PodMethods.IncrementScores | |
34 | list: PodMethods.List | |
35 | listAllIds: PodMethods.ListAllIds | |
36 | listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest | |
37 | listBadPods: PodMethods.ListBadPods | |
38 | load: PodMethods.Load | |
39 | loadByHost: PodMethods.LoadByHost | |
40 | removeAll: PodMethods.RemoveAll | |
41 | updatePodsScore: PodMethods.UpdatePodsScore | |
42 | } | |
43 | ||
44 | export interface PodAttributes { | |
45 | host?: string | |
46 | publicKey?: string | |
47 | score?: number | Sequelize.literal // Sequelize literal for 'score +' + value | |
48 | email?: string | |
49 | } | |
50 | ||
51 | export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> { | |
52 | id: number | |
53 | createdAt: Date | |
54 | updatedAt: Date | |
55 | ||
56 | toFormatedJSON: PodMethods.ToFormatedJSON, | |
57 | } | |
58 | ||
59 | export interface PodModel extends PodClass, Sequelize.Model<PodInstance, PodAttributes> {} |