@things-factory/operato-hub 4.3.8 → 4.3.15

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