aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/models/pod/pod-interface.ts
blob: 6c5aab3fa82db1971e08360d450122813f35f14b (plain) (tree)
1
2
3
4
5
6
7
8
9
                                      
                                   
 
                                             
                                                                           
                                                                     
 
                             
                                                                   
 
                                              
 
                                                                                                    
 
                                                 
 

                                                                                                             
                                                                                    
 
                                                                                                                                   
 
                                                        
 
                                                         
 
                                                                 
 
                                               

                                                                               





                                             
                                   









                                                                     
             
               
                                                                               


                                                                                                 


                 
                                              


                                                                                          
import * as Sequelize from 'sequelize'
import * as Promise from 'bluebird'

// Don't use barrel, import just what we need
import { Pod as FormattedPod } from '../../../shared/models/pods/pod.model'
import { ResultList } from '../../../shared/models/result-list.model'

export namespace PodMethods {
  export type ToFormattedJSON = (this: PodInstance) => FormattedPod

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

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

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

  export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<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
  listForApi: PodMethods.ListForApi
  listAllIds: PodMethods.ListAllIds
  listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
  listBadPods: PodMethods.ListBadPods
  load: PodMethods.Load
  loadByHost: PodMethods.LoadByHost
  removeAll: PodMethods.RemoveAll
  updatePodsScore: PodMethods.UpdatePodsScore
}

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

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

  toFormattedJSON: PodMethods.ToFormattedJSON,
}

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