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

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-05-22 13:58:25 -05:00
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', {}, {
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
}
// ---------------------------------------------------------------------------
2017-06-10 15:15:25 -05:00
removeByRequestIdsAndPod = function (requestsIds: number[], podId: number, callback?: RequestToPodMethods.RemoveByRequestIdsAndPodCallback) {
2017-05-15 15:22:03 -05:00
if (!callback) callback = function () { /* empty */ }
2016-12-11 14:50:51 -06:00
const query = {
where: {
requestId: {
$in: requestsIds
},
podId: podId
}
}
2017-05-22 13:58:25 -05:00
RequestToPod.destroy(query).asCallback(callback)
2016-12-11 14:50:51 -06:00
}