]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/request/request-to-pod.ts
Reorganize model files
[github/Chocobozzz/PeerTube.git] / server / models / request / request-to-pod.ts
CommitLineData
e02643f3
C
1import * as Sequelize from 'sequelize'
2
74889a71 3import { addMethodsToModel } from '../utils'
e02643f3
C
4import {
5 RequestToPodClass,
6 RequestToPodInstance,
7 RequestToPodAttributes,
8
9 RequestToPodMethods
10} from './request-to-pod-interface'
11
12let RequestToPod: Sequelize.Model<RequestToPodInstance, RequestToPodAttributes>
13let removeByRequestIdsAndPod: RequestToPodMethods.RemoveByRequestIdsAndPod
14
127944aa
C
15export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
16 RequestToPod = sequelize.define<RequestToPodInstance, RequestToPodAttributes>('RequestToPod', {}, {
319d072e
C
17 indexes: [
18 {
19 fields: [ 'requestId' ]
20 },
21 {
22 fields: [ 'podId' ]
23 },
24 {
25 fields: [ 'requestId', 'podId' ],
26 unique: true
27 }
e02643f3 28 ]
feb4bdfd
C
29 })
30
e02643f3
C
31 const classMethods = [
32 removeByRequestIdsAndPod
33 ]
34 addMethodsToModel(RequestToPod, classMethods)
35
feb4bdfd
C
36 return RequestToPod
37}
38
39// ---------------------------------------------------------------------------
40
69818c93 41removeByRequestIdsAndPod = function (requestsIds: number[], podId: number, callback?: RequestToPodMethods.RemoveByRequestIdsAndPodCallback) {
65fcc311 42 if (!callback) callback = function () { /* empty */ }
feb4bdfd
C
43
44 const query = {
45 where: {
46 requestId: {
47 $in: requestsIds
48 },
49 podId: podId
50 }
51 }
52
e02643f3 53 RequestToPod.destroy(query).asCallback(callback)
feb4bdfd 54}