aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/models/request-to-pod.ts
blob: 3562069cc761b17fe8c80b523301a29b9dda48d6 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                                                               










                                         
     

    




                                               




                                                                              
                                                                                                                                             
                                                       









                        
                                                  
 
import * as Sequelize from 'sequelize'

import { addMethodsToModel } from './utils'
import {
  RequestToPodClass,
  RequestToPodInstance,
  RequestToPodAttributes,

  RequestToPodMethods
} from './request-to-pod-interface'

let RequestToPod: Sequelize.Model<RequestToPodInstance, RequestToPodAttributes>
let removeByRequestIdsAndPod: RequestToPodMethods.RemoveByRequestIdsAndPod

export default function (sequelize, DataTypes) {
  RequestToPod = sequelize.define('RequestToPod', {}, {
    indexes: [
      {
        fields: [ 'requestId' ]
      },
      {
        fields: [ 'podId' ]
      },
      {
        fields: [ 'requestId', 'podId' ],
        unique: true
      }
    ]
  })

  const classMethods = [
    removeByRequestIdsAndPod
  ]
  addMethodsToModel(RequestToPod, classMethods)

  return RequestToPod
}

// ---------------------------------------------------------------------------

removeByRequestIdsAndPod = function (requestsIds: number[], podId: number, callback?: RequestToPodMethods.RemoveByRequestIdsAndPodCallback) {
  if (!callback) callback = function () { /* empty */ }

  const query = {
    where: {
      requestId: {
        $in: requestsIds
      },
      podId: podId
    }
  }

  RequestToPod.destroy(query).asCallback(callback)
}