PeerTube/server/models/request/request-to-pod.ts

52 lines
1.2 KiB
TypeScript
Raw Normal View History

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