@things-factory/operato-hub 4.3.14 → 4.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const typeorm_1 = require("typeorm");
9
9
  const api_1 = require("@things-factory/api");
10
10
  const biz_base_1 = require("@things-factory/biz-base");
11
+ const integration_base_1 = require("@things-factory/integration-base");
11
12
  const product_base_1 = require("@things-factory/product-base");
12
13
  const sales_base_1 = require("@things-factory/sales-base");
13
14
  const setting_base_1 = require("@things-factory/setting-base");
@@ -15,528 +16,567 @@ const warehouse_base_1 = require("@things-factory/warehouse-base");
15
16
  const business_middleware_1 = require("../../../../middlewares/business-middleware");
16
17
  const warehouse_middleware_1 = require("../../../../middlewares/warehouse-middleware");
17
18
  const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-release-order');
18
- api_1.restfulApiRouter.post('/unstable/warehouse/:warehouseId/add-release-order', business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
19
+ const apiVersion = 'unstable';
20
+ api_1.restfulApiRouter.post(`/${apiVersion}/warehouse/:warehouseId/add-release-order`, business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
19
21
  return await (0, typeorm_1.getConnection)().transaction(async (tx) => {
20
22
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
21
23
  const { client, domain } = context.state;
22
24
  const { warehouseId: customerBizplaceId } = context.params;
23
25
  const { t } = context;
24
- if (!customerBizplaceId)
25
- context.throw(404, t('error.warehouse id not found'));
26
- let bodyReq = context.request.body;
27
- if (typeof bodyReq === undefined || !((_a = Object.keys(bodyReq)) === null || _a === void 0 ? void 0 : _a.length)) {
28
- context.throw(400, t('error.invalid body request format'));
29
- }
30
- debug('post:/add-release-order request.body', bodyReq);
31
- await checkMandatoryKey(context, bodyReq);
32
- const isAutoAssign = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true;
33
- // get customer company's bizplace
34
- const custCompanyBizplace = await (0, biz_base_1.getCompanyBizplace)(null, null, customerBizplaceId, tx);
35
- const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
36
- where: { id: customerBizplaceId }
37
- });
38
- let locationSortingRules = [];
39
- const inventoryAssignmentSetting = await tx.getRepository(setting_base_1.Setting).findOne({
40
- where: { domain, name: 'rule-for-inventory-assignment' }
41
- });
42
- if (inventoryAssignmentSetting) {
43
- let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
44
- for (const key in locationSetting) {
45
- locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
26
+ const bodyReq = context.request.body;
27
+ try {
28
+ if (!customerBizplaceId)
29
+ context.throw(404, t('error.warehouse id not found'));
30
+ if (typeof bodyReq === undefined || !((_a = Object.keys(bodyReq)) === null || _a === void 0 ? void 0 : _a.length)) {
31
+ context.throw(400, t('error.invalid body request format'));
46
32
  }
47
- }
48
- else {
49
- const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
50
- where: { domain, name: 'rule-for-picking-product' }
33
+ debug('post:/add-release-order request.body', bodyReq);
34
+ await checkMandatoryKey(context, bodyReq);
35
+ const isAutoAssign = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true;
36
+ const requiredDraft = bodyReq.hasOwnProperty('requiredDraft') ? bodyReq.requiredDraft : true;
37
+ // get customer company's bizplace
38
+ const custCompanyBizplace = await (0, biz_base_1.getCompanyBizplace)(null, null, customerBizplaceId, tx);
39
+ const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
40
+ where: { id: customerBizplaceId }
41
+ });
42
+ let locationSortingRules = [];
43
+ const inventoryAssignmentSetting = await tx.getRepository(setting_base_1.Setting).findOne({
44
+ where: { domain, name: 'rule-for-inventory-assignment' }
51
45
  });
52
- if (pickingProductSetting) {
53
- let locationSetting = JSON.parse(pickingProductSetting.value);
46
+ if (inventoryAssignmentSetting) {
47
+ let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
54
48
  for (const key in locationSetting) {
55
49
  locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
56
50
  }
57
51
  }
58
- }
59
- const orderInventories = bodyReq.orderInventories;
60
- let newOrderInventories = [];
61
- let bundleInfo = [];
62
- await Promise.all(orderInventories.map(async (orderInventory) => {
63
- var _a, _b;
64
- const sku = (_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku;
65
- const refCode = (_b = orderInventory.product) === null || _b === void 0 ? void 0 : _b.refCode;
66
- const packingType = orderInventory.packingType;
67
- const qb = tx
68
- .getRepository(product_base_1.ProductDetail)
69
- .createQueryBuilder('PD')
70
- .innerJoinAndSelect('PD.product', 'PROD')
71
- .where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
72
- if (!sku && !refCode) {
73
- context.throw(404, t('error.sku or refCode not found'));
74
- }
75
- if (refCode) {
76
- qb.andWhere('PD.ref_code = :refCode', { refCode });
77
- }
78
- if (sku) {
79
- qb.andWhere('PROD.sku = :sku', { sku });
80
- }
81
- if (packingType) {
82
- qb.andWhere('PD.packing_type = :packingType', { packingType });
83
- }
84
- if (!packingType && !refCode) {
85
- qb.andWhere('PD.is_default = :isDefault', { isDefault: true });
86
- }
87
- const productDetail = await qb.getOne();
88
- if (productDetail) {
89
- let newOrderInventory = Object.assign({}, orderInventory);
90
- newOrderInventory.product.sku = productDetail.product.sku;
91
- newOrderInventory.product = productDetail.product;
92
- newOrderInventory.packingType = productDetail.packingType;
93
- newOrderInventory.uomValue = productDetail.uomValue;
94
- newOrderInventories.push(newOrderInventory);
52
+ else {
53
+ const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
54
+ where: { domain, name: 'rule-for-picking-product' }
55
+ });
56
+ if (pickingProductSetting) {
57
+ let locationSetting = JSON.parse(pickingProductSetting.value);
58
+ for (const key in locationSetting) {
59
+ locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
60
+ }
61
+ }
95
62
  }
96
- if (!productDetail) {
63
+ const orderInventories = bodyReq.orderInventories;
64
+ let newOrderInventories = [];
65
+ let bundleInfo = [];
66
+ await Promise.all(orderInventories.map(async (orderInventory) => {
67
+ var _a, _b;
68
+ const sku = (_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku;
69
+ const refCode = (_b = orderInventory.product) === null || _b === void 0 ? void 0 : _b.refCode;
70
+ const packingType = orderInventory.packingType;
97
71
  const qb = tx
98
- .getRepository(product_base_1.ProductBundle)
99
- .createQueryBuilder('PB')
100
- .innerJoinAndSelect('PB.productBundleSettings', 'PBS')
101
- .innerJoinAndSelect('PBS.productDetail', 'PBD')
102
- .innerJoinAndSelect('PBD.product', 'PROD')
103
- .where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
72
+ .getRepository(product_base_1.ProductDetail)
73
+ .createQueryBuilder('PD')
74
+ .innerJoinAndSelect('PD.product', 'PROD')
75
+ .where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
104
76
  if (!sku && !refCode) {
105
77
  context.throw(404, t('error.sku or refCode not found'));
106
78
  }
107
79
  if (refCode) {
108
- qb.andWhere('PB.ref_code = :refCode', { refCode });
80
+ qb.andWhere('PD.ref_code = :refCode', { refCode });
109
81
  }
110
82
  if (sku) {
111
- qb.andWhere('PB.sku = :sku', { sku });
83
+ qb.andWhere('PROD.sku = :sku', { sku });
112
84
  }
113
85
  if (packingType) {
114
- qb.andWhere('PB.packing_type = :packingType', { packingType });
86
+ qb.andWhere('PD.packing_type = :packingType', { packingType });
115
87
  }
116
- const foundProductBundle = await qb.getOne();
117
- if (foundProductBundle) {
118
- bundleInfo.push({
119
- productBundleId: foundProductBundle.id,
120
- sku: foundProductBundle.sku,
121
- releaseQty: orderInventory.releaseQty
122
- });
123
- const bundleProductSettings = foundProductBundle.productBundleSettings;
124
- bundleProductSettings.map(bundleProductSetting => {
125
- const productDetailBundle = bundleProductSetting.productDetail;
126
- let newOrderInventory = Object.assign({}, orderInventory);
127
- newOrderInventory.product.sku = productDetailBundle.product.sku;
128
- newOrderInventory.packingType = productDetailBundle.packingType;
129
- newOrderInventory.uomValue = productDetailBundle.uomValue;
130
- newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty;
131
- newOrderInventory.product = productDetailBundle.product;
132
- newOrderInventories.push(newOrderInventory);
133
- });
88
+ if (!packingType && !refCode) {
89
+ qb.andWhere('PD.is_default = :isDefault', { isDefault: true });
134
90
  }
135
- else {
136
- if (sku && refCode) {
137
- context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`));
138
- }
139
- if (sku) {
140
- context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`));
91
+ const productDetail = await qb.getOne();
92
+ if (productDetail) {
93
+ let newOrderInventory = Object.assign({}, orderInventory);
94
+ newOrderInventory.product.sku = productDetail.product.sku;
95
+ newOrderInventory.product = productDetail.product;
96
+ newOrderInventory.packingType = productDetail.packingType;
97
+ newOrderInventory.uomValue = productDetail.uomValue;
98
+ newOrderInventories.push(newOrderInventory);
99
+ }
100
+ if (!productDetail) {
101
+ const qb = tx
102
+ .getRepository(product_base_1.ProductBundle)
103
+ .createQueryBuilder('PB')
104
+ .innerJoinAndSelect('PB.productBundleSettings', 'PBS')
105
+ .innerJoinAndSelect('PBS.productDetail', 'PBD')
106
+ .innerJoinAndSelect('PBD.product', 'PROD')
107
+ .where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
108
+ if (!sku && !refCode) {
109
+ context.throw(404, t('error.sku or refCode not found'));
141
110
  }
142
111
  if (refCode) {
143
- context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`));
112
+ qb.andWhere('PB.ref_code = :refCode', { refCode });
144
113
  }
145
- }
146
- }
147
- }));
148
- let finalOrderInventories = [];
149
- // Case 1. Every order inventories has specified batch id
150
- if (newOrderInventories.every((orderInventory) => orderInventory.batchId)) {
151
- finalOrderInventories = await Promise.all(newOrderInventories.map(async (orderInventory) => {
152
- let filters = [
153
- {
154
- name: 'batchId',
155
- operator: 'eq',
156
- value: orderInventory.batchId
157
- },
158
- {
159
- name: 'productName',
160
- operator: 'eq',
161
- value: orderInventory.product.sku
162
- },
163
- {
164
- name: 'bizplace',
165
- operator: 'in',
166
- value: [customerBizplaceId]
114
+ if (sku) {
115
+ qb.andWhere('PB.sku = :sku', { sku });
167
116
  }
168
- ];
169
- let sortings = [];
170
- switch (orderInventory.product.pickingStrategy) {
171
- case 'FIFO':
172
- sortings.push({ name: 'created_at', desc: false });
173
- break;
174
- case 'LIFO':
175
- sortings.push({ name: 'created_at', desc: true });
176
- break;
177
- case 'FEFO':
178
- sortings.push({ name: 'expiration_date', desc: false });
179
- break;
180
- case 'FMFO':
181
- sortings.push({ name: 'manufacture_date', desc: false });
182
- break;
183
- }
184
- // 2. get all inventory data according to SKU and batchId
185
- const response = await client.query({
186
- query: (0, graphql_tag_1.default) `
187
- query inventoriesByPallet($filters: [Filter], $sortings: [Sorting], $locationSortingRules: [Sorting]) {
188
- inventoriesByPallet(
189
- filters: $filters
190
- sortings: $sortings
191
- locationSortingRules: $locationSortingRules
192
- ) {
193
- items {
194
- product {
195
- id
196
- name
197
- description
198
- }
199
- batchId
200
- packingType
201
- remainQty
202
- remainUomValue
117
+ if (packingType) {
118
+ qb.andWhere('PB.packing_type = :packingType', { packingType });
203
119
  }
204
- total
205
- }
206
- }
207
- `,
208
- variables: { filters, sortings, locationSortingRules },
209
- context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
210
- });
211
- if (!response.errors) {
212
- const items = response.data.inventoriesByPallet.items || [];
213
- if (!(items === null || items === void 0 ? void 0 : items.length)) {
214
- context.body = {
215
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
216
- };
217
- return;
120
+ const foundProductBundle = await qb.getOne();
121
+ if (foundProductBundle) {
122
+ bundleInfo.push({
123
+ productBundleId: foundProductBundle.id,
124
+ sku: foundProductBundle.sku,
125
+ releaseQty: orderInventory.releaseQty
126
+ });
127
+ const bundleProductSettings = foundProductBundle.productBundleSettings;
128
+ bundleProductSettings.map(bundleProductSetting => {
129
+ const productDetailBundle = bundleProductSetting.productDetail;
130
+ let newOrderInventory = Object.assign({}, orderInventory);
131
+ newOrderInventory.product.sku = productDetailBundle.product.sku;
132
+ newOrderInventory.packingType = productDetailBundle.packingType;
133
+ newOrderInventory.uomValue = productDetailBundle.uomValue;
134
+ newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty;
135
+ newOrderInventory.product = productDetailBundle.product;
136
+ newOrderInventories.push(newOrderInventory);
137
+ });
218
138
  }
219
- items.forEach(async (item) => {
220
- if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
221
- context.body = {
222
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
223
- };
224
- return;
139
+ else {
140
+ if (sku && refCode) {
141
+ context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`));
142
+ }
143
+ if (sku) {
144
+ context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`));
145
+ }
146
+ if (refCode) {
147
+ context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`));
225
148
  }
226
- // 3. add more information to orderInventory
227
- orderInventory.product.id = item.product.id;
228
- orderInventory.packingType = item.packingType;
229
- orderInventory.batchId = item.batchId;
230
- orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
231
- orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
232
- orderInventory.uom = item.uom;
233
- });
234
- return orderInventory;
235
- }
236
- else {
237
- context.body = {
238
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
239
- };
240
- return;
241
- }
242
- }));
243
- }
244
- else {
245
- // Case 2. Some of order inventories doesn't have specified batch id
246
- // MMS order doesn't have batch ID field.
247
- // To cover this case first result of found inventory will be a target of RO
248
- // To combine items from different bundles
249
- newOrderInventories = combineItems(newOrderInventories);
250
- for (let i = 0; i < newOrderInventories.length; i++) {
251
- const orderInventory = newOrderInventories[i];
252
- const { product, packingType } = orderInventory;
253
- const pickingStrategy = product.pickingStrategy;
254
- if (isAutoAssign) {
255
- let qb = tx.getRepository(warehouse_base_1.Inventory).createQueryBuilder('iv');
256
- qb.leftJoinAndSelect('iv.location', 'loc')
257
- .andWhere('"iv"."domain_id" = :domainId')
258
- .andWhere('"iv"."bizplace_id" = :bizplaceId')
259
- .andWhere('"iv"."packing_type" = :packingType')
260
- .andWhere('"iv"."product_id" = :productId')
261
- .andWhere('"iv"."status" = :status')
262
- .andWhere('"loc"."type" NOT IN (:...locationTypes)')
263
- .setParameters({
264
- domainId: domain.id,
265
- bizplaceId: customerBizplace.id,
266
- packingType: packingType,
267
- productId: product.id,
268
- status: warehouse_base_1.INVENTORY_STATUS.STORED,
269
- locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
270
- });
271
- switch (pickingStrategy) {
272
- case 'FIFO':
273
- qb.orderBy('"iv"."created_at"', 'ASC');
274
- if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
275
- locationSortingRules.forEach((rule, idx) => {
276
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
277
- });
278
- }
279
- break;
280
- case 'LIFO':
281
- qb.orderBy('"iv"."created_at"', 'DESC');
282
- if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
283
- locationSortingRules.forEach((rule, idx) => {
284
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
285
- });
286
- }
287
- break;
288
- case 'FEFO':
289
- qb.orderBy('"iv"."expiration_date"', 'ASC');
290
- if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
291
- locationSortingRules.forEach((rule, idx) => {
292
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
293
- });
294
- }
295
- break;
296
- case 'FMFO':
297
- qb.orderBy('"iv"."manufacture_date"', 'ASC');
298
- if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
299
- locationSortingRules.forEach((rule, idx) => {
300
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
301
- });
302
- }
303
- break;
304
- case 'LOCATION':
305
- if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
306
- locationSortingRules.forEach((rule, idx) => {
307
- idx === 0
308
- ? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
309
- : qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
310
- });
311
- }
312
- else {
313
- qb.orderBy('"loc"."name"', 'DESC');
314
- }
315
- break;
316
- }
317
- let inventories = await qb.getMany();
318
- if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length)) {
319
- context.body = {
320
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
321
- };
322
- return;
323
- }
324
- inventories = inventories
325
- .map(inventory => {
326
- return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - inventory.lockedQty, remainUomValue: inventory.uomValue - inventory.lockedUomValue });
327
- })
328
- .filter(inventory => inventory.remainQty > 0);
329
- let targetInventories;
330
- try {
331
- targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
332
- }
333
- catch (e) {
334
- context.body = {
335
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
336
- };
337
- return;
338
149
  }
339
- targetInventories.map(item => {
340
- finalOrderInventories.push(item.targetInventory);
341
- });
342
150
  }
343
- else {
151
+ }));
152
+ let finalOrderInventories = [];
153
+ // Case 1. Every order inventories has specified batch id
154
+ if (newOrderInventories.every((orderInventory) => orderInventory.batchId)) {
155
+ finalOrderInventories = await Promise.all(newOrderInventories.map(async (orderInventory) => {
344
156
  let filters = [
157
+ {
158
+ name: 'batchId',
159
+ operator: 'eq',
160
+ value: orderInventory.batchId
161
+ },
345
162
  {
346
163
  name: 'productName',
347
164
  operator: 'eq',
348
165
  value: orderInventory.product.sku
349
166
  },
350
167
  {
351
- name: 'bizplace_id',
352
- operator: 'eq',
353
- value: customerBizplaceId
168
+ name: 'bizplace',
169
+ operator: 'in',
170
+ value: [customerBizplaceId]
354
171
  }
355
172
  ];
173
+ let sortings = [];
174
+ switch (orderInventory.product.pickingStrategy) {
175
+ case 'FIFO':
176
+ sortings.push({ name: 'created_at', desc: false });
177
+ break;
178
+ case 'LIFO':
179
+ sortings.push({ name: 'created_at', desc: true });
180
+ break;
181
+ case 'FEFO':
182
+ sortings.push({ name: 'expiration_date', desc: false });
183
+ break;
184
+ case 'FMFO':
185
+ sortings.push({ name: 'manufacture_date', desc: false });
186
+ break;
187
+ }
356
188
  // 2. get all inventory data according to SKU and batchId
357
189
  const response = await client.query({
358
190
  query: (0, graphql_tag_1.default) `
359
- query inventoryProductGroup($filters: [Filter]) {
360
- inventoryProductGroup(filters: $filters) {
361
- items {
362
- productId
363
- productSKU
364
- productName
365
- batchId
366
- packingType
367
- remainQty
368
- remainUomValue
191
+ query inventoriesByPallet(
192
+ $filters: [Filter]
193
+ $sortings: [Sorting]
194
+ $locationSortingRules: [Sorting]
195
+ ) {
196
+ inventoriesByPallet(
197
+ filters: $filters
198
+ sortings: $sortings
199
+ locationSortingRules: $locationSortingRules
200
+ ) {
201
+ items {
202
+ product {
203
+ id
204
+ name
205
+ description
206
+ }
207
+ batchId
208
+ packingType
209
+ remainQty
210
+ remainUomValue
211
+ }
212
+ total
369
213
  }
370
- total
371
214
  }
372
- }
373
- `,
374
- variables: { filters },
215
+ `,
216
+ variables: { filters, sortings, locationSortingRules },
375
217
  context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
376
218
  });
377
219
  if (!response.errors) {
378
- const items = response.data.inventoryProductGroup.items || [];
379
- if (!(items === null || items === void 0 ? void 0 : items.length)) {
380
- context.body = {
381
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
382
- };
383
- return;
384
- }
385
- items.forEach(async (item) => {
386
- if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
220
+ const items = response.data.inventoriesByPallet.items || [];
221
+ if (requiredDraft) {
222
+ if (!(items === null || items === void 0 ? void 0 : items.length)) {
387
223
  context.body = {
388
224
  result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
389
225
  };
390
226
  return;
391
227
  }
228
+ }
229
+ items.forEach(async (item) => {
230
+ if (requiredDraft) {
231
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
232
+ context.body = {
233
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
234
+ };
235
+ return;
236
+ }
237
+ }
392
238
  // 3. add more information to orderInventory
393
- orderInventory.product = { id: item.productId };
239
+ orderInventory.product.id = item.product.id;
394
240
  orderInventory.packingType = item.packingType;
395
241
  orderInventory.batchId = item.batchId;
396
242
  orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
397
243
  orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
398
244
  orderInventory.uom = item.uom;
399
245
  });
400
- delete orderInventory.uomValue;
401
- finalOrderInventories.push(orderInventory);
246
+ return orderInventory;
402
247
  }
403
248
  else {
404
- context.body = {
405
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
406
- };
407
- return;
249
+ if (requiredDraft) {
250
+ context.body = {
251
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
252
+ };
253
+ return;
254
+ }
408
255
  }
409
- }
256
+ }));
410
257
  }
411
- }
412
- context.body = {
413
- result: (await client.mutate({
414
- mutation: (0, graphql_tag_1.default) `
415
- mutation addReleaseGood($releaseGood: NewReleaseGood, $shippingOrder: ShippingOrderPatch, $file: Upload) {
416
- addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
417
- id
418
- name
419
- refNo
420
- status
421
- truckNo
422
- ownTransport
423
- crossDocking
424
- marketplaceOrderStatus
425
- billingAddress
426
- deliveryAddress1
427
- deliveryAddress2
428
- deliveryAddress3
429
- deliveryAddress4
430
- deliveryAddress5
431
- attentionTo
432
- attentionCompany
433
- city
434
- state
435
- postalCode
436
- country
437
- phone1
438
- phone2
439
- email
440
- transporter
441
- trackingNo
442
- airwayBill
443
- invoice
444
- type
445
- storeName
446
- storeId
447
- routeId
448
- stopId
449
- arrivalNotice {
450
- name
258
+ else {
259
+ // Case 2. Some of order inventories doesn't have specified batch id
260
+ // MMS order doesn't have batch ID field.
261
+ // To cover this case first result of found inventory will be a target of RO
262
+ // To combine items from different bundles
263
+ newOrderInventories = combineItems(newOrderInventories);
264
+ for (let i = 0; i < newOrderInventories.length; i++) {
265
+ const orderInventory = newOrderInventories[i];
266
+ const { product, packingType } = orderInventory;
267
+ const pickingStrategy = product.pickingStrategy;
268
+ if (isAutoAssign) {
269
+ let qb = tx.getRepository(warehouse_base_1.Inventory).createQueryBuilder('iv');
270
+ qb.leftJoinAndSelect('iv.location', 'loc')
271
+ .andWhere('"iv"."domain_id" = :domainId')
272
+ .andWhere('"iv"."bizplace_id" = :bizplaceId')
273
+ .andWhere('"iv"."packing_type" = :packingType')
274
+ .andWhere('"iv"."product_id" = :productId')
275
+ .andWhere('"iv"."status" = :status')
276
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
277
+ .setParameters({
278
+ domainId: domain.id,
279
+ bizplaceId: customerBizplace.id,
280
+ packingType: packingType,
281
+ productId: product.id,
282
+ status: warehouse_base_1.INVENTORY_STATUS.STORED,
283
+ locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
284
+ });
285
+ switch (pickingStrategy) {
286
+ case 'FIFO':
287
+ qb.orderBy('"iv"."created_at"', 'ASC');
288
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
289
+ locationSortingRules.forEach((rule, idx) => {
290
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
291
+ });
292
+ }
293
+ break;
294
+ case 'LIFO':
295
+ qb.orderBy('"iv"."created_at"', 'DESC');
296
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
297
+ locationSortingRules.forEach((rule, idx) => {
298
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
299
+ });
300
+ }
301
+ break;
302
+ case 'FEFO':
303
+ qb.orderBy('"iv"."expiration_date"', 'ASC');
304
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
305
+ locationSortingRules.forEach((rule, idx) => {
306
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
307
+ });
308
+ }
309
+ break;
310
+ case 'FMFO':
311
+ qb.orderBy('"iv"."manufacture_date"', 'ASC');
312
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
313
+ locationSortingRules.forEach((rule, idx) => {
314
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
315
+ });
316
+ }
317
+ break;
318
+ case 'LOCATION':
319
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
320
+ locationSortingRules.forEach((rule, idx) => {
321
+ idx === 0
322
+ ? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
323
+ : qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
324
+ });
325
+ }
326
+ else {
327
+ qb.orderBy('"loc"."name"', 'DESC');
328
+ }
329
+ break;
330
+ }
331
+ let inventories = await qb.getMany();
332
+ if (requiredDraft) {
333
+ if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length)) {
334
+ context.body = {
335
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
336
+ };
337
+ return;
338
+ }
339
+ }
340
+ inventories = inventories
341
+ .map(inventory => {
342
+ return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - inventory.lockedQty, remainUomValue: inventory.uomValue - inventory.lockedUomValue });
343
+ })
344
+ .filter(inventory => inventory.remainQty > 0);
345
+ let targetInventories;
346
+ try {
347
+ targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
348
+ }
349
+ catch (e) {
350
+ if (requiredDraft) {
351
+ context.body = {
352
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
353
+ };
354
+ return;
355
+ }
356
+ else {
357
+ targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
358
+ }
359
+ }
360
+ if (!(targetInventories === null || targetInventories === void 0 ? void 0 : targetInventories.length)) {
361
+ context.throw(404, t(`error.no inventories found`));
362
+ }
363
+ targetInventories.map(item => {
364
+ finalOrderInventories.push(item.targetInventory);
365
+ });
366
+ }
367
+ else {
368
+ let filters = [
369
+ {
370
+ name: 'productName',
371
+ operator: 'eq',
372
+ value: orderInventory.product.sku
373
+ },
374
+ {
375
+ name: 'bizplace_id',
376
+ operator: 'eq',
377
+ value: customerBizplaceId
378
+ }
379
+ ];
380
+ // 2. get all inventory data according to SKU and batchId
381
+ const response = await client.query({
382
+ query: (0, graphql_tag_1.default) `
383
+ query inventoryProductGroup($filters: [Filter]) {
384
+ inventoryProductGroup(filters: $filters) {
385
+ items {
386
+ productId
387
+ productSKU
388
+ productName
389
+ batchId
390
+ packingType
391
+ remainQty
392
+ remainUomValue
393
+ }
394
+ total
395
+ }
451
396
  }
452
- exportOption
453
- releaseDate
454
- collectionOrderNo
455
- bizplace {
397
+ `,
398
+ variables: { filters },
399
+ context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
400
+ });
401
+ if (!response.errors) {
402
+ const items = response.data.inventoryProductGroup.items || [];
403
+ if (requiredDraft) {
404
+ if (!(items === null || items === void 0 ? void 0 : items.length)) {
405
+ context.body = {
406
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
407
+ };
408
+ return;
409
+ }
410
+ }
411
+ items.forEach(async (item) => {
412
+ if (requiredDraft) {
413
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
414
+ context.body = {
415
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
416
+ };
417
+ return;
418
+ }
419
+ }
420
+ // 3. add more information to orderInventory
421
+ orderInventory.product = { id: item.productId };
422
+ orderInventory.packingType = item.packingType;
423
+ orderInventory.batchId = item.batchId;
424
+ orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
425
+ orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
426
+ orderInventory.uom = item.uom;
427
+ });
428
+ delete orderInventory.uomValue;
429
+ finalOrderInventories.push(orderInventory);
430
+ }
431
+ else {
432
+ if (requiredDraft) {
433
+ context.body = {
434
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
435
+ };
436
+ return;
437
+ }
438
+ }
439
+ }
440
+ }
441
+ }
442
+ context.body = {
443
+ result: (await client.mutate({
444
+ mutation: (0, graphql_tag_1.default) `
445
+ mutation addReleaseGood(
446
+ $releaseGood: NewReleaseGood
447
+ $shippingOrder: ShippingOrderPatch
448
+ $file: Upload
449
+ ) {
450
+ addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
451
+ id
456
452
  name
457
- }
458
- orderInventories {
459
- product {
460
- sku
453
+ refNo
454
+ status
455
+ truckNo
456
+ ownTransport
457
+ crossDocking
458
+ marketplaceOrderStatus
459
+ billingAddress
460
+ deliveryAddress1
461
+ deliveryAddress2
462
+ deliveryAddress3
463
+ deliveryAddress4
464
+ deliveryAddress5
465
+ attentionTo
466
+ attentionCompany
467
+ city
468
+ state
469
+ postalCode
470
+ country
471
+ phone1
472
+ phone2
473
+ email
474
+ transporter
475
+ trackingNo
476
+ airwayBill
477
+ invoice
478
+ type
479
+ storeName
480
+ storeId
481
+ routeId
482
+ stopId
483
+ arrivalNotice {
461
484
  name
462
- description
463
485
  }
464
- batchId
465
- packingType
466
- packingSize
467
- releaseQty
468
- releaseUomValue
469
- }
470
- orderVass {
471
- vas {
486
+ exportOption
487
+ releaseDate
488
+ collectionOrderNo
489
+ bizplace {
472
490
  name
473
- operationGuide
474
- operationGuideType
475
491
  }
476
- set
477
- targetType
478
- targetBatchId
479
- targetProduct {
480
- name
492
+ orderInventories {
493
+ product {
494
+ sku
495
+ name
496
+ description
497
+ }
498
+ batchId
499
+ packingType
500
+ packingSize
501
+ releaseQty
502
+ releaseUomValue
503
+ }
504
+ orderVass {
505
+ vas {
506
+ name
507
+ operationGuide
508
+ operationGuideType
509
+ }
510
+ set
511
+ targetType
512
+ targetBatchId
513
+ targetProduct {
514
+ name
515
+ description
516
+ }
517
+ packingType
518
+ qty
519
+ uomValue
520
+ otherTarget
481
521
  description
522
+ remark
523
+ status
524
+ operationGuide
482
525
  }
483
- packingType
484
- qty
485
- uomValue
486
- otherTarget
487
- description
488
- remark
489
- status
490
- operationGuide
491
526
  }
492
527
  }
493
- }
494
- `,
495
- variables: {
496
- releaseGood: {
497
- customerBizplaceId: customerBizplace.id,
498
- courierOption: bodyReq.courierOption,
499
- collectionOrderNo: bodyReq.collectionOrderNo,
500
- exportOption: bodyReq.exportOption,
501
- orderInventories: finalOrderInventories,
502
- ownTransport: bodyReq.ownTransport,
503
- packingOption: bodyReq.packingOption,
504
- refNo: bodyReq.refNo,
505
- refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
506
- releaseDate: bodyReq.releaseDate,
507
- type: bodyReq.type,
508
- marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
509
- remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
510
- billingAddress: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _b === void 0 ? void 0 : _b.billingAddress) || null,
511
- deliveryAddress1: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress1) || null,
512
- deliveryAddress2: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress2) || null,
513
- deliveryAddress3: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress3) || null,
514
- deliveryAddress4: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress4) || null,
515
- deliveryAddress5: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress5) || null,
516
- attentionTo: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionTo) || null,
517
- attentionCompany: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionCompany) || null,
518
- city: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.city) || null,
519
- state: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.state) || null,
520
- postalCode: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.postalCode) || null,
521
- country: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.country) || null,
522
- phone1: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone1) || null,
523
- phone2: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone2) || null,
524
- email: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.email) || null,
525
- transporter: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.transporter,
526
- trackingNo: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.trackingNo,
527
- airwayBill: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.airwayBill,
528
- invoice: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.invoice,
529
- bundleInfo: JSON.stringify(bundleInfo),
530
- storeName: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeName,
531
- storeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeId,
532
- routeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.routeId,
533
- stopId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.stopId
534
- }
535
- },
536
- context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
537
- domain, type: 'api' }) })
538
- })).data
539
- };
528
+ `,
529
+ variables: {
530
+ releaseGood: {
531
+ customerBizplaceId: customerBizplace.id,
532
+ courierOption: bodyReq.courierOption,
533
+ collectionOrderNo: bodyReq.collectionOrderNo,
534
+ exportOption: bodyReq.exportOption,
535
+ orderInventories: finalOrderInventories,
536
+ ownTransport: bodyReq.ownTransport,
537
+ packingOption: bodyReq.packingOption,
538
+ refNo: bodyReq.refNo,
539
+ refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
540
+ releaseDate: bodyReq.releaseDate,
541
+ type: bodyReq.type,
542
+ marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
543
+ remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
544
+ billingAddress: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _b === void 0 ? void 0 : _b.billingAddress) || null,
545
+ deliveryAddress1: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress1) || null,
546
+ deliveryAddress2: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress2) || null,
547
+ deliveryAddress3: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress3) || null,
548
+ deliveryAddress4: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress4) || null,
549
+ deliveryAddress5: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress5) || null,
550
+ attentionTo: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionTo) || null,
551
+ attentionCompany: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionCompany) || null,
552
+ city: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.city) || null,
553
+ state: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.state) || null,
554
+ postalCode: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.postalCode) || null,
555
+ country: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.country) || null,
556
+ phone1: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone1) || null,
557
+ phone2: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone2) || null,
558
+ email: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.email) || null,
559
+ transporter: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.transporter,
560
+ trackingNo: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.trackingNo,
561
+ airwayBill: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.airwayBill,
562
+ invoice: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.invoice,
563
+ bundleInfo: JSON.stringify(bundleInfo),
564
+ storeName: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeName,
565
+ storeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeId,
566
+ routeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.routeId,
567
+ stopId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.stopId
568
+ }
569
+ },
570
+ context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
571
+ domain, type: 'api' }) })
572
+ })).data
573
+ };
574
+ (0, integration_base_1.createPayloadLog)(customerBizplaceId, `/${apiVersion}/warehouse/:warehouseId/add-release-order`, bodyReq, context.body, context, integration_base_1.PayloadType.INGESTION);
575
+ }
576
+ catch (error) {
577
+ (0, integration_base_1.createPayloadLog)(customerBizplaceId, `/${apiVersion}/warehouse/:warehouseId/add-release-order`, bodyReq, error, context, integration_base_1.PayloadType.INGESTION);
578
+ throw error;
579
+ }
540
580
  });
541
581
  });
542
582
  async function checkMandatoryKey(context, params) {