2017-05-22 14:58:25 -04:00
|
|
|
import * as Sequelize from 'sequelize'
|
|
|
|
|
2017-06-16 03:45:46 -04:00
|
|
|
import { addMethodsToModel } from '../utils'
|
2017-05-22 14:58:25 -04:00
|
|
|
import {
|
|
|
|
RequestToPodClass,
|
|
|
|
RequestToPodInstance,
|
|
|
|
RequestToPodAttributes,
|
|
|
|
|
|
|
|
RequestToPodMethods
|
|
|
|
} from './request-to-pod-interface'
|
|
|
|
|
|
|
|
let RequestToPod: Sequelize.Model<RequestToPodInstance, RequestToPodAttributes>
|
|
|
|
let removeByRequestIdsAndPod: RequestToPodMethods.RemoveByRequestIdsAndPod
|
|
|
|
|
2017-06-11 11:35:32 -04:00
|
|
|
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
|
|
|
|
RequestToPod = sequelize.define<RequestToPodInstance, RequestToPodAttributes>('RequestToPod', {}, {
|
2016-12-29 03:33:28 -05:00
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'requestId' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'podId' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'requestId', 'podId' ],
|
|
|
|
unique: true
|
|
|
|
}
|
2017-05-22 14:58:25 -04:00
|
|
|
]
|
2016-12-11 15:50:51 -05:00
|
|
|
})
|
|
|
|
|
2017-05-22 14:58:25 -04:00
|
|
|
const classMethods = [
|
|
|
|
removeByRequestIdsAndPod
|
|
|
|
]
|
|
|
|
addMethodsToModel(RequestToPod, classMethods)
|
|
|
|
|
2016-12-11 15:50:51 -05:00
|
|
|
return RequestToPod
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-06-10 16:15:25 -04:00
|
|
|
removeByRequestIdsAndPod = function (requestsIds: number[], podId: number, callback?: RequestToPodMethods.RemoveByRequestIdsAndPodCallback) {
|
2017-05-15 16:22:03 -04:00
|
|
|
if (!callback) callback = function () { /* empty */ }
|
2016-12-11 15:50:51 -05:00
|
|
|
|
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
requestId: {
|
|
|
|
$in: requestsIds
|
|
|
|
},
|
|
|
|
podId: podId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 14:58:25 -04:00
|
|
|
RequestToPod.destroy(query).asCallback(callback)
|
2016-12-11 15:50:51 -05:00
|
|
|
}
|