aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request/request-to-pod.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/request/request-to-pod.ts')
-rw-r--r--server/models/request/request-to-pod.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/server/models/request/request-to-pod.ts b/server/models/request/request-to-pod.ts
new file mode 100644
index 000000000..67331be1d
--- /dev/null
+++ b/server/models/request/request-to-pod.ts
@@ -0,0 +1,54 @@
1import * as Sequelize from 'sequelize'
2
3import { addMethodsToModel } from '../utils'
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
15export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
16 RequestToPod = sequelize.define<RequestToPodInstance, RequestToPodAttributes>('RequestToPod', {}, {
17 indexes: [
18 {
19 fields: [ 'requestId' ]
20 },
21 {
22 fields: [ 'podId' ]
23 },
24 {
25 fields: [ 'requestId', 'podId' ],
26 unique: true
27 }
28 ]
29 })
30
31 const classMethods = [
32 removeByRequestIdsAndPod
33 ]
34 addMethodsToModel(RequestToPod, classMethods)
35
36 return RequestToPod
37}
38
39// ---------------------------------------------------------------------------
40
41removeByRequestIdsAndPod = function (requestsIds: number[], podId: number, callback?: RequestToPodMethods.RemoveByRequestIdsAndPodCallback) {
42 if (!callback) callback = function () { /* empty */ }
43
44 const query = {
45 where: {
46 requestId: {
47 $in: requestsIds
48 },
49 podId: podId
50 }
51 }
52
53 RequestToPod.destroy(query).asCallback(callback)
54}