@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,541 +8,575 @@ 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
- api_1.restfulApiRouter.post('/v2/warehouse/:warehouseId/add-release-order', business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
18
+ const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-release-order');
19
+ const apiVersion = 'v2';
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, 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);
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
+ }
98
62
  }
99
- 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;
100
71
  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 });
72
+ .getRepository(product_base_1.ProductDetail)
73
+ .createQueryBuilder('PD')
74
+ .innerJoinAndSelect('PD.product', 'PROD')
75
+ .where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
107
76
  if (!sku && !refCode) {
108
77
  context.throw(404, t('error.sku or refCode not found'));
109
78
  }
110
79
  if (refCode) {
111
- qb.andWhere('PB.ref_code = :refCode', { refCode });
80
+ qb.andWhere('PD.ref_code = :refCode', { refCode });
112
81
  }
113
82
  if (sku) {
114
- qb.andWhere('PB.sku = :sku', { sku });
83
+ qb.andWhere('PROD.sku = :sku', { sku });
115
84
  }
116
85
  if (packingType) {
117
- qb.andWhere('PB.packing_type = :packingType', { packingType });
86
+ qb.andWhere('PD.packing_type = :packingType', { packingType });
118
87
  }
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
- });
88
+ if (!packingType && !refCode) {
89
+ qb.andWhere('PD.is_default = :isDefault', { isDefault: true });
137
90
  }
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`));
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'));
144
110
  }
145
111
  if (refCode) {
146
- context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`));
112
+ qb.andWhere('PB.ref_code = :refCode', { refCode });
147
113
  }
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]
114
+ if (sku) {
115
+ qb.andWhere('PB.sku = :sku', { sku });
170
116
  }
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
117
+ if (packingType) {
118
+ qb.andWhere('PB.packing_type = :packingType', { packingType });
206
119
  }
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;
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
+ });
221
138
  }
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;
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`));
228
148
  }
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
149
  }
342
- targetInventories.map(item => {
343
- finalOrderInventories.push(item.targetInventory);
344
- });
345
- targetInventories.map(item => {
346
- finalOrderInventories.push(item.targetInventory);
347
- });
348
150
  }
349
- 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) => {
350
156
  let filters = [
157
+ {
158
+ name: 'batchId',
159
+ operator: 'eq',
160
+ value: orderInventory.batchId
161
+ },
351
162
  {
352
163
  name: 'productName',
353
164
  operator: 'eq',
354
165
  value: orderInventory.product.sku
355
166
  },
356
167
  {
357
- name: 'bizplace_id',
358
- operator: 'eq',
359
- value: customerBizplaceId
168
+ name: 'bizplace',
169
+ operator: 'in',
170
+ value: [customerBizplaceId]
360
171
  }
361
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
+ }
362
188
  // 2. get all inventory data according to SKU and batchId
363
189
  const response = await client.query({
364
190
  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
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
375
213
  }
376
- total
377
214
  }
378
- }
379
- `,
380
- variables: { filters },
215
+ `,
216
+ variables: { filters, sortings, locationSortingRules },
381
217
  context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
382
218
  });
383
219
  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) {
220
+ const items = response.data.inventoriesByPallet.items || [];
221
+ if (requiredDraft) {
222
+ if (!(items === null || items === void 0 ? void 0 : items.length)) {
393
223
  context.body = {
394
224
  result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
395
225
  };
396
226
  return;
397
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
+ }
398
238
  // 3. add more information to orderInventory
399
- orderInventory.product = { id: item.productId };
239
+ orderInventory.product.id = item.product.id;
400
240
  orderInventory.packingType = item.packingType;
401
241
  orderInventory.batchId = item.batchId;
402
242
  orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
403
243
  orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
404
244
  orderInventory.uom = item.uom;
405
245
  });
406
- delete orderInventory.uomValue;
407
- finalOrderInventories.push(orderInventory);
246
+ return orderInventory;
408
247
  }
409
248
  else {
410
- context.body = {
411
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
412
- };
413
- return;
249
+ if (requiredDraft) {
250
+ context.body = {
251
+ result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
252
+ };
253
+ return;
254
+ }
414
255
  }
415
- }
256
+ }));
416
257
  }
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
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
+ }
457
396
  }
458
- exportOption
459
- releaseDate
460
- collectionOrderNo
461
- 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
462
452
  name
463
- }
464
- orderInventories {
465
- product {
466
- 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 {
467
484
  name
468
- description
469
485
  }
470
- batchId
471
- packingType
472
- packingSize
473
- releaseQty
474
- releaseUomValue
475
- }
476
- orderVass {
477
- vas {
486
+ exportOption
487
+ releaseDate
488
+ collectionOrderNo
489
+ bizplace {
478
490
  name
479
- operationGuide
480
- operationGuideType
481
491
  }
482
- set
483
- targetType
484
- targetBatchId
485
- targetProduct {
486
- 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
487
521
  description
522
+ remark
523
+ status
524
+ operationGuide
488
525
  }
489
- packingType
490
- qty
491
- uomValue
492
- otherTarget
493
- description
494
- remark
495
- status
496
- operationGuide
497
526
  }
498
527
  }
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
- };
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
+ }
546
580
  });
547
581
  });
548
582
  async function checkMandatoryKey(context, params) {
@@ -595,7 +629,7 @@ function _composeTargetInventories(context, product, record, inventories) {
595
629
  totalInventoryQty += inventory.remainQty;
596
630
  });
597
631
  if (totalInventoryQty < record.releaseQty) {
598
- context.throw(404, t(`error.invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`));
632
+ context.throw(404, t(`error.invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`)); //
599
633
  }
600
634
  let targetInventories = [];
601
635
  let idx = 0;