@things-factory/operato-hub 4.3.19 → 4.4.0-alpha.3

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.
Files changed (65) hide show
  1. package/client/pages/constants/setting.js +0 -1
  2. package/dist-server/controllers/bizplace-initializer/dataset/codes.js +0 -9
  3. package/dist-server/controllers/bizplace-initializer/dataset/codes.js.map +1 -1
  4. package/dist-server/controllers/bizplace-initializer/dataset/index.js +5 -1
  5. package/dist-server/controllers/bizplace-initializer/dataset/index.js.map +1 -1
  6. package/dist-server/controllers/bizplace-initializer/dataset/settings.js +0 -10
  7. package/dist-server/controllers/bizplace-initializer/dataset/settings.js.map +1 -1
  8. package/dist-server/controllers/bizplace-initializer/index.js +5 -1
  9. package/dist-server/controllers/bizplace-initializer/index.js.map +1 -1
  10. package/dist-server/controllers/company-initializer/index.js +5 -1
  11. package/dist-server/controllers/company-initializer/index.js.map +1 -1
  12. package/dist-server/graphql/index.js +5 -1
  13. package/dist-server/graphql/index.js.map +1 -1
  14. package/dist-server/graphql/resolvers/index.js +5 -1
  15. package/dist-server/graphql/resolvers/index.js.map +1 -1
  16. package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js +50 -82
  17. package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js.map +1 -1
  18. package/dist-server/graphql/types/index.js +5 -1
  19. package/dist-server/graphql/types/index.js.map +1 -1
  20. package/dist-server/index.js +5 -1
  21. package/dist-server/index.js.map +1 -1
  22. package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js +75 -85
  23. package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js.map +1 -1
  24. package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +424 -576
  25. package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
  26. package/dist-server/routers/api/restful-apis/unstable/index.js +0 -1
  27. package/dist-server/routers/api/restful-apis/unstable/index.js.map +1 -1
  28. package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js +75 -85
  29. package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js.map +1 -1
  30. package/dist-server/routers/api/restful-apis/v1/add-release-order.js +428 -577
  31. package/dist-server/routers/api/restful-apis/v1/add-release-order.js.map +1 -1
  32. package/dist-server/routers/api/restful-apis/v1/index.js +0 -1
  33. package/dist-server/routers/api/restful-apis/v1/index.js.map +1 -1
  34. package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js +75 -85
  35. package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js.map +1 -1
  36. package/dist-server/routers/api/restful-apis/v2/add-release-order.js +428 -577
  37. package/dist-server/routers/api/restful-apis/v2/add-release-order.js.map +1 -1
  38. package/dist-server/routers/api/restful-apis/v2/index.js +0 -1
  39. package/dist-server/routers/api/restful-apis/v2/index.js.map +1 -1
  40. package/dist-server/routers/business/index.js +5 -1
  41. package/dist-server/routers/business/index.js.map +1 -1
  42. package/dist-server/utils/index.js +5 -1
  43. package/dist-server/utils/index.js.map +1 -1
  44. package/package.json +55 -55
  45. package/server/controllers/bizplace-initializer/dataset/codes.ts +0 -9
  46. package/server/controllers/bizplace-initializer/dataset/settings.ts +0 -10
  47. package/server/graphql/resolvers/synchronization/sync-products-to-sellercraft.ts +57 -89
  48. package/server/routers/api/restful-apis/unstable/add-marketplace-order.ts +85 -97
  49. package/server/routers/api/restful-apis/unstable/add-release-order.ts +499 -734
  50. package/server/routers/api/restful-apis/unstable/index.ts +0 -1
  51. package/server/routers/api/restful-apis/v1/add-marketplace-order.ts +85 -97
  52. package/server/routers/api/restful-apis/v1/add-release-order.ts +504 -735
  53. package/server/routers/api/restful-apis/v1/index.ts +0 -1
  54. package/server/routers/api/restful-apis/v2/add-marketplace-order.ts +85 -97
  55. package/server/routers/api/restful-apis/v2/add-release-order.ts +503 -735
  56. package/server/routers/api/restful-apis/v2/index.ts +0 -1
  57. package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js +0 -171
  58. package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js.map +0 -1
  59. package/dist-server/routers/api/restful-apis/v1/add-draft-release-order.js +0 -171
  60. package/dist-server/routers/api/restful-apis/v1/add-draft-release-order.js.map +0 -1
  61. package/dist-server/routers/api/restful-apis/v2/add-draft-release-order.js +0 -171
  62. package/dist-server/routers/api/restful-apis/v2/add-draft-release-order.js.map +0 -1
  63. package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +0 -196
  64. package/server/routers/api/restful-apis/v1/add-draft-release-order.ts +0 -196
  65. package/server/routers/api/restful-apis/v2/add-draft-release-order.ts +0 -196
@@ -8,7 +8,6 @@ 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");
12
11
  const product_base_1 = require("@things-factory/product-base");
13
12
  const sales_base_1 = require("@things-factory/sales-base");
14
13
  const setting_base_1 = require("@things-factory/setting-base");
@@ -16,567 +15,496 @@ const warehouse_base_1 = require("@things-factory/warehouse-base");
16
15
  const business_middleware_1 = require("../../../../middlewares/business-middleware");
17
16
  const warehouse_middleware_1 = require("../../../../middlewares/warehouse-middleware");
18
17
  const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-release-order');
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) => {
18
+ api_1.restfulApiRouter.post('/unstable/warehouse/:warehouseId/add-release-order', business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
21
19
  return await (0, typeorm_1.getConnection)().transaction(async (tx) => {
22
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
20
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
23
21
  const { client, domain } = context.state;
24
22
  const { warehouseId: customerBizplaceId } = context.params;
25
23
  const { t } = context;
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'));
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 });
32
46
  }
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' }
47
+ }
48
+ else {
49
+ const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
50
+ where: { domain, name: 'rule-for-picking-product' }
45
51
  });
46
- if (inventoryAssignmentSetting) {
47
- let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
52
+ if (pickingProductSetting) {
53
+ let locationSetting = JSON.parse(pickingProductSetting.value);
48
54
  for (const key in locationSetting) {
49
55
  locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
50
56
  }
51
57
  }
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
- }
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'));
62
74
  }
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;
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);
95
+ }
96
+ if (!productDetail) {
71
97
  const qb = tx
72
- .getRepository(product_base_1.ProductDetail)
73
- .createQueryBuilder('PD')
74
- .innerJoinAndSelect('PD.product', 'PROD')
75
- .where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
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 });
76
104
  if (!sku && !refCode) {
77
105
  context.throw(404, t('error.sku or refCode not found'));
78
106
  }
79
107
  if (refCode) {
80
- qb.andWhere('PD.ref_code = :refCode', { refCode });
108
+ qb.andWhere('PB.ref_code = :refCode', { refCode });
81
109
  }
82
110
  if (sku) {
83
- qb.andWhere('PROD.sku = :sku', { sku });
111
+ qb.andWhere('PB.sku = :sku', { sku });
84
112
  }
85
113
  if (packingType) {
86
- qb.andWhere('PD.packing_type = :packingType', { packingType });
114
+ qb.andWhere('PB.packing_type = :packingType', { packingType });
87
115
  }
88
- if (!packingType && !refCode) {
89
- qb.andWhere('PD.is_default = :isDefault', { isDefault: true });
90
- }
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);
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
+ });
99
134
  }
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'));
110
- }
111
- if (refCode) {
112
- qb.andWhere('PB.ref_code = :refCode', { refCode });
135
+ else {
136
+ if (sku && refCode) {
137
+ context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`));
113
138
  }
114
139
  if (sku) {
115
- qb.andWhere('PB.sku = :sku', { sku });
140
+ context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`));
116
141
  }
117
- if (packingType) {
118
- qb.andWhere('PB.packing_type = :packingType', { packingType });
142
+ if (refCode) {
143
+ context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`));
119
144
  }
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
- });
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
+ var _a;
153
+ let filters = [
154
+ {
155
+ name: 'batchId',
156
+ operator: 'eq',
157
+ value: orderInventory.batchId
158
+ },
159
+ {
160
+ name: 'productName',
161
+ operator: 'eq',
162
+ value: orderInventory.product.sku
163
+ },
164
+ {
165
+ name: 'bizplace',
166
+ operator: 'in',
167
+ value: [customerBizplaceId]
138
168
  }
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`));
148
- }
169
+ ];
170
+ let sortings = [];
171
+ switch (orderInventory.product.pickingStrategy) {
172
+ case 'FIFO':
173
+ sortings.push({ name: 'created_at', desc: false });
174
+ break;
175
+ case 'LIFO':
176
+ sortings.push({ name: 'created_at', desc: true });
177
+ break;
178
+ case 'FEFO':
179
+ sortings.push({ name: 'expiration_date', desc: false });
180
+ break;
181
+ case 'FMFO':
182
+ sortings.push({ name: 'manufacture_date', desc: false });
183
+ break;
184
+ }
185
+ // 2. get all inventory data according to SKU and batchId
186
+ const response = await client.query({
187
+ query: (0, graphql_tag_1.default) `
188
+ query inventoriesByPallet($filters: [Filter], $sortings: [Sorting], $locationSortingRules: [Sorting]) {
189
+ inventoriesByPallet(
190
+ filters: $filters
191
+ sortings: $sortings
192
+ locationSortingRules: $locationSortingRules
193
+ ) {
194
+ items {
195
+ product {
196
+ id
197
+ name
198
+ description
199
+ }
200
+ batchId
201
+ packingType
202
+ remainQty
203
+ remainUomValue
149
204
  }
205
+ total
206
+ }
150
207
  }
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) => {
156
- let filters = [
157
- {
158
- name: 'batchId',
159
- operator: 'eq',
160
- value: orderInventory.batchId
161
- },
162
- {
163
- name: 'productName',
164
- operator: 'eq',
165
- value: orderInventory.product.sku
166
- },
167
- {
168
- name: 'bizplace',
169
- operator: 'in',
170
- value: [customerBizplaceId]
208
+ `,
209
+ variables: { filters, sortings, locationSortingRules },
210
+ context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
211
+ });
212
+ if (!response.errors) {
213
+ const items = response.data.inventoriesByPallet.items || [];
214
+ if (!(items === null || items === void 0 ? void 0 : items.length))
215
+ context.throw(404, t(`error.no inventories found for ${(_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku} with batch ID ${orderInventory === null || orderInventory === void 0 ? void 0 : orderInventory.batchId}`));
216
+ items.forEach(item => {
217
+ var _a;
218
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
219
+ context.throw(404, t(`error.invalid release qty for ${(_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku}`));
171
220
  }
172
- ];
173
- let sortings = [];
174
- switch (orderInventory.product.pickingStrategy) {
221
+ // 3. add more information to orderInventory
222
+ orderInventory.product.id = item.product.id;
223
+ orderInventory.packingType = item.packingType;
224
+ orderInventory.batchId = item.batchId;
225
+ orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
226
+ orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
227
+ orderInventory.uom = item.uom;
228
+ });
229
+ return orderInventory;
230
+ }
231
+ else
232
+ context.throw(404, t('error.failed to fetch inventory'));
233
+ }));
234
+ }
235
+ else {
236
+ // Case 2. Some of order inventories doesn't have specified batch id
237
+ // MMS order doesn't have batch ID field.
238
+ // To cover this case first result of found inventory will be a target of RO
239
+ // To combine items from different bundles
240
+ newOrderInventories = combineItems(newOrderInventories);
241
+ for (let i = 0; i < newOrderInventories.length; i++) {
242
+ const orderInventory = newOrderInventories[i];
243
+ const { product, packingType } = orderInventory;
244
+ const pickingStrategy = product.pickingStrategy;
245
+ if (isAutoAssign) {
246
+ let qb = tx.getRepository(warehouse_base_1.Inventory).createQueryBuilder('iv');
247
+ qb.leftJoinAndSelect('iv.location', 'loc')
248
+ .andWhere('"iv"."domain_id" = :domainId')
249
+ .andWhere('"iv"."bizplace_id" = :bizplaceId')
250
+ .andWhere('"iv"."packing_type" = :packingType')
251
+ .andWhere('"iv"."product_id" = :productId')
252
+ .andWhere('"iv"."status" = :status')
253
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
254
+ .setParameters({
255
+ domainId: domain.id,
256
+ bizplaceId: customerBizplace.id,
257
+ packingType: packingType,
258
+ productId: product.id,
259
+ status: warehouse_base_1.INVENTORY_STATUS.STORED,
260
+ locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
261
+ });
262
+ switch (pickingStrategy) {
175
263
  case 'FIFO':
176
- sortings.push({ name: 'created_at', desc: false });
264
+ qb.orderBy('"iv"."created_at"', 'ASC');
265
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
266
+ locationSortingRules.forEach((rule, idx) => {
267
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
268
+ });
269
+ }
177
270
  break;
178
271
  case 'LIFO':
179
- sortings.push({ name: 'created_at', desc: true });
272
+ qb.orderBy('"iv"."created_at"', 'DESC');
273
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
274
+ locationSortingRules.forEach((rule, idx) => {
275
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
276
+ });
277
+ }
180
278
  break;
181
279
  case 'FEFO':
182
- sortings.push({ name: 'expiration_date', desc: false });
280
+ qb.orderBy('"iv"."expiration_date"', 'ASC');
281
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
282
+ locationSortingRules.forEach((rule, idx) => {
283
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
284
+ });
285
+ }
183
286
  break;
184
287
  case 'FMFO':
185
- sortings.push({ name: 'manufacture_date', desc: false });
288
+ qb.orderBy('"iv"."manufacture_date"', 'ASC');
289
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
290
+ locationSortingRules.forEach((rule, idx) => {
291
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
292
+ });
293
+ }
294
+ break;
295
+ case 'LOCATION':
296
+ if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
297
+ locationSortingRules.forEach((rule, idx) => {
298
+ idx === 0
299
+ ? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
300
+ : qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
301
+ });
302
+ }
303
+ else {
304
+ qb.orderBy('"loc"."name"', 'DESC');
305
+ }
186
306
  break;
187
307
  }
308
+ let inventories = await qb.getMany();
309
+ if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length))
310
+ context.throw(404, t(`error.no inventories found for ${product.sku}`));
311
+ inventories = inventories
312
+ .map(inventory => {
313
+ return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - inventory.lockedQty, remainUomValue: inventory.uomValue - inventory.lockedUomValue });
314
+ })
315
+ .filter(inventory => inventory.remainQty > 0);
316
+ const targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
317
+ targetInventories.map(item => {
318
+ finalOrderInventories.push(item.targetInventory);
319
+ });
320
+ }
321
+ else {
322
+ let filters = [
323
+ {
324
+ name: 'productName',
325
+ operator: 'eq',
326
+ value: orderInventory.product.sku
327
+ },
328
+ {
329
+ name: 'bizplace_id',
330
+ operator: 'eq',
331
+ value: customerBizplaceId
332
+ }
333
+ ];
188
334
  // 2. get all inventory data according to SKU and batchId
189
335
  const response = await client.query({
190
336
  query: (0, graphql_tag_1.default) `
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
337
+ query inventoryProductGroup($filters: [Filter]) {
338
+ inventoryProductGroup(filters: $filters) {
339
+ items {
340
+ productId
341
+ productSKU
342
+ productName
343
+ batchId
344
+ packingType
345
+ remainQty
346
+ remainUomValue
213
347
  }
348
+ total
214
349
  }
215
- `,
216
- variables: { filters, sortings, locationSortingRules },
350
+ }
351
+ `,
352
+ variables: { filters },
217
353
  context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
218
354
  });
219
355
  if (!response.errors) {
220
- const items = response.data.inventoriesByPallet.items || [];
221
- if (requiredDraft) {
222
- if (!(items === null || items === void 0 ? void 0 : items.length)) {
223
- context.body = {
224
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
225
- };
226
- return;
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
- }
356
+ const items = response.data.inventoryProductGroup.items || [];
357
+ if (!(items === null || items === void 0 ? void 0 : items.length))
358
+ context.throw(404, t(`error.no inventories found for ${(_b = orderInventory.product) === null || _b === void 0 ? void 0 : _b.sku} with batch ID ${orderInventory === null || orderInventory === void 0 ? void 0 : orderInventory.batchId}`));
359
+ items.forEach(item => {
360
+ var _a;
361
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
362
+ context.throw(404, t(`error.invalid release qty for ${(_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku}`));
237
363
  }
238
364
  // 3. add more information to orderInventory
239
- orderInventory.product.id = item.product.id;
365
+ orderInventory.product = { id: item.productId };
240
366
  orderInventory.packingType = item.packingType;
241
367
  orderInventory.batchId = item.batchId;
242
368
  orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
243
369
  orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
244
370
  orderInventory.uom = item.uom;
245
371
  });
246
- return orderInventory;
247
- }
248
- else {
249
- if (requiredDraft) {
250
- context.body = {
251
- result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
252
- };
253
- return;
254
- }
255
- }
256
- }));
257
- }
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
- }
396
- }
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
- }
372
+ delete orderInventory.uomValue;
373
+ finalOrderInventories.push(orderInventory);
439
374
  }
375
+ else
376
+ context.throw(404, t('error.failed to fetch inventory'));
440
377
  }
441
378
  }
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
379
+ }
380
+ context.body = {
381
+ result: (await client.mutate({
382
+ mutation: (0, graphql_tag_1.default) `
383
+ mutation addReleaseGood($releaseGood: NewReleaseGood, $shippingOrder: ShippingOrderPatch, $file: Upload) {
384
+ addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
385
+ id
386
+ name
387
+ refNo
388
+ status
389
+ truckNo
390
+ ownTransport
391
+ crossDocking
392
+ marketplaceOrderStatus
393
+ billingAddress
394
+ deliveryAddress1
395
+ deliveryAddress2
396
+ deliveryAddress3
397
+ deliveryAddress4
398
+ deliveryAddress5
399
+ attentionTo
400
+ attentionCompany
401
+ city
402
+ state
403
+ postalCode
404
+ country
405
+ phone1
406
+ phone2
407
+ email
408
+ transporter
409
+ trackingNo
410
+ airwayBill
411
+ invoice
412
+ type
413
+ storeName
414
+ storeId
415
+ routeId
416
+ stopId
417
+ arrivalNotice {
452
418
  name
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 {
419
+ }
420
+ exportOption
421
+ releaseDate
422
+ collectionOrderNo
423
+ bizplace {
424
+ name
425
+ }
426
+ orderInventories {
427
+ product {
428
+ sku
484
429
  name
430
+ description
485
431
  }
486
- exportOption
487
- releaseDate
488
- collectionOrderNo
489
- bizplace {
432
+ batchId
433
+ packingType
434
+ packingSize
435
+ releaseQty
436
+ releaseUomValue
437
+ }
438
+ orderVass {
439
+ vas {
490
440
  name
441
+ operationGuide
442
+ operationGuideType
491
443
  }
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
444
+ set
445
+ targetType
446
+ targetBatchId
447
+ targetProduct {
448
+ name
521
449
  description
522
- remark
523
- status
524
- operationGuide
525
450
  }
451
+ packingType
452
+ qty
453
+ uomValue
454
+ otherTarget
455
+ description
456
+ remark
457
+ status
458
+ operationGuide
526
459
  }
527
460
  }
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
- }
461
+ }
462
+ `,
463
+ variables: {
464
+ releaseGood: {
465
+ customerBizplaceId: customerBizplace.id,
466
+ courierOption: bodyReq.courierOption,
467
+ collectionOrderNo: bodyReq.collectionOrderNo,
468
+ exportOption: bodyReq.exportOption,
469
+ orderInventories: finalOrderInventories,
470
+ ownTransport: bodyReq.ownTransport,
471
+ packingOption: bodyReq.packingOption,
472
+ refNo: bodyReq.refNo,
473
+ refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
474
+ releaseDate: bodyReq.releaseDate,
475
+ type: bodyReq.type,
476
+ marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
477
+ remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
478
+ billingAddress: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _c === void 0 ? void 0 : _c.billingAddress) || null,
479
+ deliveryAddress1: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress1) || null,
480
+ deliveryAddress2: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress2) || null,
481
+ deliveryAddress3: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress3) || null,
482
+ deliveryAddress4: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress4) || null,
483
+ deliveryAddress5: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.deliveryAddress5) || null,
484
+ attentionTo: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionTo) || null,
485
+ attentionCompany: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.attentionCompany) || null,
486
+ city: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.city) || null,
487
+ state: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.state) || null,
488
+ postalCode: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.postalCode) || null,
489
+ country: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.country) || null,
490
+ phone1: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone1) || null,
491
+ phone2: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.phone2) || null,
492
+ email: ((_s = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _s === void 0 ? void 0 : _s.email) || null,
493
+ transporter: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.transporter,
494
+ trackingNo: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.trackingNo,
495
+ airwayBill: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.airwayBill,
496
+ invoice: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.invoice,
497
+ bundleInfo: JSON.stringify(bundleInfo),
498
+ storeName: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeName,
499
+ storeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeId,
500
+ routeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.routeId,
501
+ stopId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.stopId
502
+ }
503
+ },
504
+ context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
505
+ domain, type: 'api' }) })
506
+ })).data
507
+ };
580
508
  });
581
509
  });
582
510
  async function checkMandatoryKey(context, params) {
@@ -629,7 +557,7 @@ function _composeTargetInventories(context, product, record, inventories) {
629
557
  totalInventoryQty += inventory.remainQty;
630
558
  });
631
559
  if (totalInventoryQty < record.releaseQty) {
632
- context.throw(404, t(`error.invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`)); //
560
+ context.throw(404, t(`error.invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`));
633
561
  }
634
562
  let targetInventories = [];
635
563
  let idx = 0;
@@ -689,84 +617,4 @@ function combineItems(inventoryList) {
689
617
  });
690
618
  return mappedList;
691
619
  }
692
- async function createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx) {
693
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
694
- return (await client.mutate({
695
- mutation: (0, graphql_tag_1.default) `
696
- mutation upsertDraftReleaseGood(
697
- $draftReleaseGood: DraftReleaseGoodPatch!
698
- $orderProducts: [OrderProductPatch!]!
699
- ) {
700
- upsertDraftReleaseGood(draftReleaseGood: $draftReleaseGood, orderProducts: $orderProducts) {
701
- id
702
- name
703
- refNo
704
- refNo2
705
- status
706
- truckNo
707
- ownTransport
708
- marketplaceOrderStatus
709
- billingAddress
710
- deliveryAddress1
711
- deliveryAddress2
712
- deliveryAddress3
713
- deliveryAddress4
714
- deliveryAddress5
715
- attentionTo
716
- attentionCompany
717
- city
718
- state
719
- postalCode
720
- country
721
- phone1
722
- phone2
723
- email
724
- type
725
- exportOption
726
- releaseDate
727
- collectionOrderNo
728
- bizplace {
729
- name
730
- }
731
- }
732
- }
733
- `,
734
- variables: {
735
- draftReleaseGood: {
736
- bizplace: {
737
- id: customerBizplace.id
738
- },
739
- courierOption: bodyReq.courierOption,
740
- collectionOrderNo: bodyReq.collectionOrderNo,
741
- exportOption: bodyReq.exportOption,
742
- ownTransport: bodyReq.ownTransport,
743
- packingOption: bodyReq.packingOption,
744
- refNo: bodyReq.refNo,
745
- refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
746
- releaseDate: bodyReq.releaseDate,
747
- type: bodyReq.type,
748
- marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
749
- remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
750
- billingAddress: ((_a = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _a === void 0 ? void 0 : _a.billingAddress) || null,
751
- deliveryAddress1: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _b === void 0 ? void 0 : _b.deliveryAddress1) || null,
752
- deliveryAddress2: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress2) || null,
753
- deliveryAddress3: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress3) || null,
754
- deliveryAddress4: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress4) || null,
755
- deliveryAddress5: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress5) || null,
756
- attentionTo: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.attentionTo) || null,
757
- attentionCompany: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionCompany) || null,
758
- city: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.city) || null,
759
- state: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.state) || null,
760
- postalCode: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.postalCode) || null,
761
- country: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.country) || null,
762
- phone1: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.phone1) || null,
763
- phone2: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone2) || null,
764
- email: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.email) || null
765
- },
766
- orderProducts: orderInventories
767
- },
768
- context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
769
- domain, type: 'api' }) })
770
- })).data;
771
- }
772
620
  //# sourceMappingURL=add-release-order.js.map