]>
Commit | Line | Data |
---|---|---|
e02643f3 C |
1 | import * as Sequelize from 'sequelize' |
2 | ||
74889a71 | 3 | import { addMethodsToModel } from '../utils' |
e02643f3 | 4 | import { |
e02643f3 C |
5 | RequestToPodInstance, |
6 | RequestToPodAttributes, | |
7 | ||
8 | RequestToPodMethods | |
9 | } from './request-to-pod-interface' | |
10 | ||
11 | let RequestToPod: Sequelize.Model<RequestToPodInstance, RequestToPodAttributes> | |
12 | let removeByRequestIdsAndPod: RequestToPodMethods.RemoveByRequestIdsAndPod | |
13 | ||
127944aa C |
14 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
15 | RequestToPod = sequelize.define<RequestToPodInstance, RequestToPodAttributes>('RequestToPod', {}, { | |
319d072e C |
16 | indexes: [ |
17 | { | |
18 | fields: [ 'requestId' ] | |
19 | }, | |
20 | { | |
21 | fields: [ 'podId' ] | |
22 | }, | |
23 | { | |
24 | fields: [ 'requestId', 'podId' ], | |
25 | unique: true | |
26 | } | |
e02643f3 | 27 | ] |
feb4bdfd C |
28 | }) |
29 | ||
e02643f3 C |
30 | const classMethods = [ |
31 | removeByRequestIdsAndPod | |
32 | ] | |
33 | addMethodsToModel(RequestToPod, classMethods) | |
34 | ||
feb4bdfd C |
35 | return RequestToPod |
36 | } | |
37 | ||
38 | // --------------------------------------------------------------------------- | |
39 | ||
6fcd19ba | 40 | removeByRequestIdsAndPod = function (requestsIds: number[], podId: number) { |
feb4bdfd C |
41 | const query = { |
42 | where: { | |
43 | requestId: { | |
44 | $in: requestsIds | |
45 | }, | |
46 | podId: podId | |
47 | } | |
48 | } | |
49 | ||
6fcd19ba | 50 | return RequestToPod.destroy(query) |
feb4bdfd | 51 | } |