@things-factory/operato-hub 4.3.366 → 4.3.368

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 (22) hide show
  1. package/dist-server/routers/api/restful-apis/v1/company/index.js +1 -0
  2. package/dist-server/routers/api/restful-apis/v1/company/index.js.map +1 -1
  3. package/dist-server/routers/api/restful-apis/v1/company/upsert-product.js +227 -0
  4. package/dist-server/routers/api/restful-apis/v1/company/upsert-product.js.map +1 -0
  5. package/dist-server/routers/api/restful-apis/v1/utils/params.js +81 -1
  6. package/dist-server/routers/api/restful-apis/v1/utils/params.js.map +1 -1
  7. package/dist-server/routers/api/restful-apis/v1/warehouse/dispatch-delivery-order.js +17 -16
  8. package/dist-server/routers/api/restful-apis/v1/warehouse/dispatch-delivery-order.js.map +1 -1
  9. package/dist-server/routers/api/restful-apis/v1/warehouse/get-manifest-details.js +138 -0
  10. package/dist-server/routers/api/restful-apis/v1/warehouse/get-manifest-details.js.map +1 -0
  11. package/dist-server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.js +2 -0
  12. package/dist-server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.js.map +1 -1
  13. package/dist-server/routers/api/restful-apis/v1/warehouse/index.js +1 -0
  14. package/dist-server/routers/api/restful-apis/v1/warehouse/index.js.map +1 -1
  15. package/package.json +14 -14
  16. package/server/routers/api/restful-apis/v1/company/index.ts +1 -0
  17. package/server/routers/api/restful-apis/v1/company/upsert-product.ts +322 -0
  18. package/server/routers/api/restful-apis/v1/utils/params.ts +81 -1
  19. package/server/routers/api/restful-apis/v1/warehouse/dispatch-delivery-order.ts +10 -10
  20. package/server/routers/api/restful-apis/v1/warehouse/get-manifest-details.ts +140 -0
  21. package/server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.ts +2 -0
  22. package/server/routers/api/restful-apis/v1/warehouse/index.ts +1 -0
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_1 = __importDefault(require("lodash"));
7
+ const typeorm_1 = require("typeorm");
8
+ const api_1 = require("@things-factory/api");
9
+ const sales_base_1 = require("@things-factory/sales-base");
10
+ // import { OrderPackage } from '@things-factory/sales-base'
11
+ const middlewares_1 = require("../middlewares");
12
+ const error_util_1 = require("../utils/error-util");
13
+ api_1.restfulApiRouter.get('/v1/warehouse/get-manifest-details', middlewares_1.businessMiddleware, middlewares_1.validationMiddleware, middlewares_1.loggingMiddleware, async (context, next) => {
14
+ try {
15
+ // get contact points for that bizplace
16
+ // optional query parameter filter
17
+ let filter = Object.assign({}, context.query);
18
+ const { fromDate, toDate, offset, limit } = filter;
19
+ if (lodash_1.default.has(filter, 'id')) {
20
+ filter['id'] = filter['id'];
21
+ delete filter['name'];
22
+ }
23
+ else if (lodash_1.default.has(filter, 'name')) {
24
+ filter['name'] = filter['name'];
25
+ delete filter['id'];
26
+ }
27
+ else {
28
+ throw new error_util_1.ApiError('E03', 'id or name');
29
+ }
30
+ const rb = (0, typeorm_1.getRepository)(sales_base_1.Manifest)
31
+ .createQueryBuilder('mf')
32
+ .innerJoinAndSelect('mf.orderPackages', 'op')
33
+ .innerJoinAndSelect('op.releaseGood', 'rg')
34
+ .innerJoinAndSelect('op.bizplace', 'bz')
35
+ .innerJoinAndSelect('op.orderPackageItems', 'opi')
36
+ .innerJoinAndSelect('opi.orderProduct', 'opr')
37
+ .innerJoinAndSelect('opr.productDetail', 'pd')
38
+ .innerJoinAndSelect('pd.product', 'p')
39
+ .where(`op.bizplace_id = :bizplaceId`, { bizplaceId: filter.bizplaceId });
40
+ if (filter.id) {
41
+ rb.andWhere(`mf.id = :id`, { id: filter.id });
42
+ }
43
+ else if (filter.name) {
44
+ rb.andWhere(`mf.name = :name`, { name: filter.name });
45
+ }
46
+ const result = await rb.getOne();
47
+ let data;
48
+ if (result) {
49
+ data = {
50
+ id: result.id,
51
+ name: result.name,
52
+ dispatchedAt: result.dispatchedAt,
53
+ dispatcherIdentity: result.dispatcherIdentity,
54
+ dispatcherName: result.dispatcherName,
55
+ shippingProvider: result.shippingProvider,
56
+ totalOrderPackages: result.orderPackages.length,
57
+ orderPackages: result.orderPackages.map(op => {
58
+ return {
59
+ airwayBill: op.airwayBill,
60
+ dispatchmentStatus: op.dispatchmentStatus,
61
+ id: op.id,
62
+ lastMileDeliveryId: op.lastMileDeliveryId,
63
+ lmdOption: op.lmdOption,
64
+ manifestId: op.manifestId,
65
+ manifestedAt: op.manifestedAt,
66
+ name: op.name,
67
+ packageId: op.packageId,
68
+ parcelId: op.parcelId,
69
+ status: op.status,
70
+ trackingNo: op.trackingNo,
71
+ transporter: op.transporter,
72
+ orderPackageItems: op.orderPackageItems.map(opi => {
73
+ return {
74
+ name: opi.name,
75
+ id: opi.id,
76
+ packedQty: opi.packedQty,
77
+ releaseQty: opi.releaseQty,
78
+ orderProduct: {
79
+ packingSize: opi.orderProduct.packingSize,
80
+ packingType: opi.orderProduct.packingType,
81
+ releaseQty: opi.orderProduct.releaseQty,
82
+ releaseUomValue: opi.orderProduct.releaseUomValue,
83
+ uom: opi.orderProduct.uom,
84
+ uomValue: opi.orderProduct.uomValue,
85
+ packedQty: opi.orderProduct.packedQty,
86
+ productDetail: {
87
+ id: opi.orderProduct.productDetail.id,
88
+ name: opi.orderProduct.productDetail.name,
89
+ grossWeight: opi.orderProduct.productDetail.grossWeight,
90
+ nettWeight: opi.orderProduct.productDetail.nettWeight,
91
+ weightUnit: opi.orderProduct.productDetail.weightUnit,
92
+ uom: opi.orderProduct.productDetail.uom,
93
+ uomValue: opi.orderProduct.productDetail.uomValue,
94
+ packingSize: opi.orderProduct.productDetail.packingSize,
95
+ packingType: opi.orderProduct.productDetail.packingType,
96
+ product: {
97
+ id: opi.orderProduct.productDetail.product.id,
98
+ name: opi.orderProduct.productDetail.product.name,
99
+ sku: opi.orderProduct.productDetail.product.sku,
100
+ weight: opi.orderProduct.productDetail.product.weight,
101
+ weightUnit: opi.orderProduct.productDetail.product.weightUnit
102
+ }
103
+ }
104
+ }
105
+ };
106
+ }),
107
+ releaseGood: {
108
+ id: op.releaseGood.id,
109
+ name: op.releaseGood.name,
110
+ refNo: op.releaseGood.refNo,
111
+ refNo2: op.releaseGood.refNo2,
112
+ refNo3: op.releaseGood.refNo3,
113
+ shippingFee: op.releaseGood.shippingFee,
114
+ transporter: op.releaseGood.transporter
115
+ },
116
+ bizplace: {
117
+ id: op.bizplace.id,
118
+ name: op.bizplace.name
119
+ }
120
+ };
121
+ })
122
+ };
123
+ }
124
+ else {
125
+ data = {};
126
+ }
127
+ context.body = {
128
+ data
129
+ };
130
+ }
131
+ catch (e) {
132
+ if (e instanceof error_util_1.ApiError)
133
+ (0, error_util_1.ApiErrorHandler)(context, e);
134
+ else
135
+ (0, error_util_1.throwInternalServerError)(context, e);
136
+ }
137
+ });
138
+ //# sourceMappingURL=get-manifest-details.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-manifest-details.js","sourceRoot":"","sources":["../../../../../../server/routers/api/restful-apis/v1/warehouse/get-manifest-details.ts"],"names":[],"mappings":";;;;;AAAA,oDAAsB;AACtB,qCAA2D;AAE3D,6CAAgE;AAChE,2DAAqD;AAErD,4DAA4D;AAC5D,gDAA4F;AAC5F,oDAAyF;AAEzF,sBAAM,CAAC,GAAG,CACR,oCAAoC,EACpC,gCAAkB,EAClB,kCAAoB,EACpB,+BAAiB,EACjB,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACtB,IAAI;QACF,uCAAuC;QACvC,kCAAkC;QAClC,IAAI,MAAM,qBAAQ,OAAO,CAAC,KAAK,CAAE,CAAA;QACjC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;QAElD,IAAI,gBAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAA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,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU;yCAC9D;qCACF;iCACF;6BACF,CAAA;wBACH,CAAC,CAAC;wBACF,WAAW,EAAE;4BACX,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE;4BACrB,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI;4BACzB,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK;4BAC3B,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM;4BAC7B,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM;4BAC7B,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,WAAW;4BACvC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,WAAW;yBACxC;wBACD,QAAQ,EAAE;4BACR,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE;4BAClB,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI;yBACvB;qBACF,CAAA;gBACH,CAAC,CAAC;aACH,CAAA;SACF;aAAM;YACL,IAAI,GAAG,EAAE,CAAA;SACV;QAED,OAAO,CAAC,IAAI,GAAG;YACb,IAAI;SACL,CAAA;KACF;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,YAAY,qBAAQ;YAAE,IAAA,4BAAe,EAAC,OAAO,EAAE,CAAC,CAAC,CAAA;;YACjD,IAAA,qCAAwB,EAAC,OAAO,EAAE,CAAC,CAAC,CAAA;KAC1C;AACH,CAAC,CACF,CAAA"}
@@ -56,6 +56,8 @@ api_1.restfulApiRouter.get('/v1/warehouse/get-onhand-inventory-list', middleware
56
56
  packingType: inventory.packingType,
57
57
  packingSize: inventory.packingSize,
58
58
  qty: inventory.qty,
59
+ uom: inventory.uom,
60
+ uomValue: inventory.uomValue,
59
61
  reservedQty: inventory.lockedQty,
60
62
  expirationDate: inventory.expirationDate,
61
63
  weight: inventory.product.weight
@@ -1 +1 @@
1
- {"version":3,"file":"get-onhand-inventory-list.js","sourceRoot":"","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E,CAAC,CAAC,CAAA;KAC1C;AACH,CAAC,CACF,CAAA"}
1
+ {"version":3,"file":"get-onhand-inventory-list.js","sourceRoot":"","sources":["../../../../../../server/routers/api/restful-apis/v1/warehouse/get-onhand-inventory-list.ts"],"names":[],"mappings":";;;;;AAAA,oDAAsB;AACtB,qCAIgB;AAEhB,6CAAgE;AAChE,mEAA0D;AAE1D,gDAIuB;AACvB,oDAI4B;AAE5B,sBAAM,CAAC,GAAG,CACR,yCAAyC,EACzC,gCAAkB,EAClB,kCAAoB,EACpB,+BAAiB,EACjB,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IACtB,IAAI;QACF,IAAI,MAAM,qBAAQ,OAAO,CAAC,KAAK,CAAE,CAAA;QACjC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;QAClD,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAA;QACzC,OAAO,MAAM,CAAC,YAAY,CAAC,CAAA;QAC3B,IAAI,gBAAC,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;YACxB,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;YACvC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;SACrB;QAED,IAAI,QAAQ,IAAI,MAAM,EAAE;YACtB,MAAM,CAAC,WAAW,CAAC,GAAG,IAAA,iBAAO,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;SAChD;aAAM,IAAI,QAAQ,EAAE;YACnB,MAAM,CAAC,WAAW,CAAC,GAAG,IAAA,iBAAO,EAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;SACpD;aAAM,IAAI,MAAM,EAAE;YACjB,MAAM,CAAC,WAAW,CAAC,GAAG,IAAA,yBAAe,EAAC,MAAM,CAAC,CAAA;SAC9C;aAAM;YACL,MAAM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YACL,MAAM;SACP,CAAA;KACF;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,YAAY,qBAAQ;YAAE,IAAA,4BAAe,EAAC,OAAO,EAAE,CAAC,CAAC,CAAA;;YACjD,IAAA,qCAAwB,EAAC,OAAO,EAAE,CAAC,CAAC,CAAA;KAC1C;AACH,CAAC,CACF,CAAA"}
@@ -20,4 +20,5 @@ require("./get-do-document");
20
20
  require("./dispatch-delivery-order");
21
21
  require("./update-gan-to-arrived");
22
22
  require("./complete-delivery-order");
23
+ require("./get-manifest-details");
23
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../server/routers/api/restful-apis/v1/warehouse/index.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,+BAA4B;AAC5B,kCAA+B;AAC/B,kCAA+B;AAC/B,qCAAkC;AAClC,kCAA+B;AAC/B,0CAAuC;AACvC,uCAAoC;AACpC,oCAAiC;AACjC,8CAA2C;AAC3C,uCAAoC;AACpC,uCAAoC;AACpC,oCAAiC;AACjC,uDAAoD;AACpD,0CAAuC;AACvC,8BAA2B;AAC3B,6BAA0B;AAC1B,qCAAkC;AAClC,mCAAgC;AAChC,qCAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../server/routers/api/restful-apis/v1/warehouse/index.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,+BAA4B;AAC5B,kCAA+B;AAC/B,kCAA+B;AAC/B,qCAAkC;AAClC,kCAA+B;AAC/B,0CAAuC;AACvC,uCAAoC;AACpC,oCAAiC;AACjC,8CAA2C;AAC3C,uCAAoC;AACpC,uCAAoC;AACpC,oCAAiC;AACjC,uDAAoD;AACpD,0CAAuC;AACvC,8BAA2B;AAC3B,6BAA0B;AAC1B,qCAAkC;AAClC,mCAAgC;AAChC,qCAAkC;AAClC,kCAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/operato-hub",
3
- "version": "4.3.366",
3
+ "version": "4.3.368",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -77,22 +77,22 @@
77
77
  "@things-factory/i18n-base": "^4.3.281",
78
78
  "@things-factory/import-ui": "^4.3.281",
79
79
  "@things-factory/import-ui-excel": "^4.3.281",
80
- "@things-factory/integration-accounting": "^4.3.357",
81
- "@things-factory/integration-fulfillment": "^4.3.344",
82
- "@things-factory/integration-lmd": "^4.3.366",
83
- "@things-factory/integration-marketplace": "^4.3.366",
84
- "@things-factory/integration-pos": "^4.3.344",
85
- "@things-factory/integration-powrup": "^4.3.366",
86
- "@things-factory/integration-sellercraft": "^4.3.366",
87
- "@things-factory/integration-sftp": "^4.3.344",
80
+ "@things-factory/integration-accounting": "^4.3.367",
81
+ "@things-factory/integration-fulfillment": "^4.3.367",
82
+ "@things-factory/integration-lmd": "^4.3.367",
83
+ "@things-factory/integration-marketplace": "^4.3.367",
84
+ "@things-factory/integration-pos": "^4.3.367",
85
+ "@things-factory/integration-powrup": "^4.3.367",
86
+ "@things-factory/integration-sellercraft": "^4.3.367",
87
+ "@things-factory/integration-sftp": "^4.3.367",
88
88
  "@things-factory/lite-menu": "^4.3.344",
89
- "@things-factory/marketplace-base": "^4.3.366",
89
+ "@things-factory/marketplace-base": "^4.3.367",
90
90
  "@things-factory/more-ui": "^4.3.281",
91
91
  "@things-factory/notification": "^4.3.281",
92
92
  "@things-factory/pdf": "^4.3.281",
93
93
  "@things-factory/product-ui": "^4.3.357",
94
94
  "@things-factory/resource-ui": "^4.3.281",
95
- "@things-factory/sales-base": "^4.3.366",
95
+ "@things-factory/sales-base": "^4.3.367",
96
96
  "@things-factory/scene-data-transform": "^4.3.281",
97
97
  "@things-factory/scene-excel": "^4.3.281",
98
98
  "@things-factory/scene-firebase": "^4.3.281",
@@ -107,8 +107,8 @@
107
107
  "@things-factory/setting-ui": "^4.3.281",
108
108
  "@things-factory/shell": "^4.3.281",
109
109
  "@things-factory/system-ui": "^4.3.281",
110
- "@things-factory/warehouse-base": "^4.3.366",
111
- "@things-factory/worksheet-base": "^4.3.366",
110
+ "@things-factory/warehouse-base": "^4.3.367",
111
+ "@things-factory/worksheet-base": "^4.3.368",
112
112
  "cron-parser": "^4.7.0",
113
113
  "koa2-swagger-ui": "^5.0.2",
114
114
  "swagger-jsdoc": "^5.0.0",
@@ -120,5 +120,5 @@
120
120
  "resolutions": {
121
121
  "core-js": "^3.16.0"
122
122
  },
123
- "gitHead": "b6e42a97a2f2f249fc6be0d2026690c309f8bfe7"
123
+ "gitHead": "179ea4bed69193b67379d92b8cc0c6ef8311e55f"
124
124
  }
@@ -4,3 +4,4 @@ import './get-bizplace-list'
4
4
  import './get-contact-point-list'
5
5
  import './get-partner-list'
6
6
  import './get-product-list'
7
+ import './upsert-product'
@@ -0,0 +1,322 @@
1
+ import _ from 'lodash'
2
+ import {
3
+ EntityManager,
4
+ getConnection,
5
+ getRepository,
6
+ In
7
+ } from 'typeorm'
8
+
9
+ import { restfulApiRouter as router } from '@things-factory/api'
10
+ import { Bizplace } from '@things-factory/biz-base'
11
+ import {
12
+ Product,
13
+ ProductBarcode,
14
+ ProductDetail
15
+ } from '@things-factory/product-base'
16
+
17
+ import {
18
+ businessMiddleware,
19
+ loggingMiddleware,
20
+ validationMiddleware
21
+ } from '../middlewares'
22
+ import {
23
+ ApiError,
24
+ ApiErrorHandler,
25
+ throwInternalServerError
26
+ } from '../utils/error-util'
27
+
28
+ router.post(
29
+ '/v1/company/upsert-product',
30
+ businessMiddleware,
31
+ validationMiddleware,
32
+ loggingMiddleware,
33
+ async (context, next) => {
34
+ try {
35
+ await getConnection().transaction(async (tx: EntityManager) => {
36
+ if (!Array.isArray(context.request.body.data)) throw new ApiError('E01', 'data field is not an array')
37
+ let params = { ...context.query }
38
+ let productInfo = context.request.body.data
39
+ const skus = productInfo.map(p => p.sku)
40
+ const { user, domain } = context.state
41
+ let response = []
42
+ let newSku = []
43
+ let existingSku = []
44
+ let checkSku
45
+
46
+ if (!skus) {
47
+ throw new ApiError('E03', 'sku')
48
+ }
49
+
50
+ let duplicateSku = skus.filter((item, index) => skus.indexOf(item) != index)
51
+
52
+ if (duplicateSku?.length > 0) {
53
+ throw new ApiError('E05', `duplicated products found: ${[...new Set(duplicateSku)]}`)
54
+ }
55
+
56
+ //get bizplace
57
+ let bizplace = await getRepository(Bizplace).findOne({
58
+ where: {
59
+ domain
60
+ }
61
+ })
62
+
63
+ //check Existing sku
64
+ checkSku = await getRepository(Product).find({
65
+ where: {
66
+ sku: In(skus),
67
+ bizplace
68
+ },
69
+ relations: ['productDetails', 'productDetails.productBarcodes']
70
+ })
71
+
72
+ //separate between existingSku and newSku
73
+ for (const product of productInfo) {
74
+ const skuExists = checkSku.some(existingProduct => existingProduct.sku === product.sku)
75
+
76
+ if (!(product?.productDetails?.length > 0)) {
77
+ throw new ApiError('E01', 'missing product detail')
78
+ }
79
+
80
+ if (skuExists) {
81
+ existingSku.push(product)
82
+ } else {
83
+ newSku.push(product)
84
+ }
85
+ }
86
+
87
+ if (existingSku.length > 0) {
88
+ //update product
89
+ await Promise.all(
90
+ existingSku.map(async p => {
91
+ let product = p
92
+ let matchingSku = checkSku.find(itm => itm.sku == p.sku)
93
+ const productDetails = p.productDetails
94
+ product.id = matchingSku.id
95
+ product.domain = domain
96
+ product.bizplace = bizplace
97
+ product.updater = user
98
+ delete product.productDetails
99
+
100
+ let result = await tx.getRepository(Product).save(product)
101
+
102
+ let pds = await Promise.all(
103
+ productDetails.map(async pd => {
104
+ let productBarcodes = pd.productBarcodes
105
+ delete pd.productBarcodes
106
+ if (pd.packingSize < 0) throw new ApiError('E01', `${pd.gtin}: packing size cannot be negative`)
107
+ const productDetail = pd
108
+ const matchingPd = checkSku.map(itm => {
109
+ const matchingProductDetail = itm.productDetails.find(prodDetail => {
110
+ return (
111
+ prodDetail.packingSize === pd.packingSize &&
112
+ prodDetail.packingType === pd.packingType &&
113
+ prodDetail.uom === pd.uom
114
+ )
115
+ })
116
+
117
+ return { matchingProductDetail }
118
+ })
119
+ let pdResult: ProductDetail
120
+
121
+ const foundIndex = matchingPd.findIndex(itm => itm.matchingProductDetail)
122
+ if (foundIndex != -1) {
123
+ pdResult = await tx.getRepository(ProductDetail).save({
124
+ ...productDetail,
125
+ id: matchingPd[foundIndex].matchingProductDetail.id,
126
+ name: productDetail.gtin,
127
+ product: result,
128
+ childProductDetail: null,
129
+ childQty: 0,
130
+ creatorId: matchingPd[foundIndex].matchingProductDetail.creatorId,
131
+ domain: domain,
132
+ updater: user
133
+ })
134
+ } else {
135
+ pdResult = await tx.getRepository(ProductDetail).save({
136
+ ...productDetail,
137
+ name: productDetail.gtin,
138
+ product: result,
139
+ childProductDetail: null,
140
+ childQty: 0,
141
+ creator: user,
142
+ domain: domain,
143
+ updater: user
144
+ })
145
+ }
146
+
147
+ delete pdResult.creator
148
+ delete pdResult.updater
149
+ delete pdResult.product
150
+ delete pdResult.domain
151
+
152
+ let pbs: ProductBarcode[]
153
+ productBarcodes = productBarcodes.filter(barcode => Object.keys(barcode).length > 0)
154
+
155
+ if (productBarcodes.length > 0) {
156
+ pbs = await Promise.all(
157
+ productBarcodes.map(async pb => {
158
+ let existingPb: ProductBarcode
159
+ existingPb = await tx.getRepository(ProductBarcode).findOne({
160
+ where: {
161
+ gtin: pb.gtin,
162
+ productDetail: pdResult.id
163
+ }
164
+ })
165
+
166
+ if (existingPb) {
167
+ // Update existing productBarcode
168
+ pdResult.productBarcodes = pdResult.productBarcodes || []
169
+ pdResult.productBarcodes.push(pb.gtin)
170
+ return tx.getRepository(ProductBarcode).update(existingPb.id, {
171
+ ...pb,
172
+ product: result,
173
+ productDetail: pdResult.id,
174
+ updater: user
175
+ })
176
+ } else {
177
+ // Create a new productBarcode
178
+ pdResult.productBarcodes = pdResult.productBarcodes || []
179
+ pdResult.productBarcodes.push(pb.gtin)
180
+ return tx.getRepository(ProductBarcode).save({
181
+ gtin: pb.gtin ? pb.gtin : result.sku,
182
+ product: result,
183
+ productDetail: pdResult,
184
+ domain,
185
+ creator: user,
186
+ updater: user
187
+ })
188
+ }
189
+ })
190
+ )
191
+ } else {
192
+ let existingPb: ProductBarcode
193
+ existingPb = await tx.getRepository(ProductBarcode).findOne({
194
+ where: {
195
+ gtin: result.sku,
196
+ productDetail: pdResult.id
197
+ }
198
+ })
199
+ if (!existingPb) {
200
+ pbs = [
201
+ {
202
+ gtin: result.sku,
203
+ product,
204
+ productDetail: pdResult,
205
+ domain,
206
+ creator: user,
207
+ updater: user
208
+ }
209
+ ]
210
+
211
+ await tx.getRepository(ProductBarcode).save(pbs)
212
+
213
+ pdResult.productBarcodes = pbs.map(pb => pb.gtin)
214
+ }
215
+
216
+ if (existingPb) {
217
+ pdResult.productBarcodes = [existingPb.gtin]
218
+ }
219
+ }
220
+
221
+ return pdResult
222
+ })
223
+ )
224
+ delete result.creator
225
+ delete result.updater
226
+ delete result.bizplace
227
+ delete result.domain
228
+ response.push({ ...result, productDetails: pds })
229
+ })
230
+ )
231
+ }
232
+
233
+ //add new product
234
+ if (newSku.length > 0) {
235
+ await Promise.all(
236
+ newSku.map(async p => {
237
+ let product = p
238
+ const productDetails = p.productDetails
239
+
240
+ product.domain = domain
241
+ product.bizplace = bizplace
242
+ product.creator = user
243
+ product.updater = user
244
+ delete product.productDetails
245
+
246
+ let result = await tx.getRepository(Product).save(product)
247
+
248
+ // save product details
249
+ let pds = await Promise.all(
250
+ productDetails.map(async pd => {
251
+ if (pd.packingSize < 0) throw new ApiError('E01', `${pd.gtin}: packing size cannot be negative`)
252
+ const productDetail = pd
253
+ const productBarcodes = productDetail.productBarcodes
254
+ let pdResult = await tx.getRepository(ProductDetail).save({
255
+ ...productDetail,
256
+ name: productDetail.gtin,
257
+ product: result,
258
+ childProductDetail: null,
259
+ childQty: 0,
260
+ domain: domain,
261
+ creator: user,
262
+ updater: user
263
+ })
264
+ delete pdResult.creator
265
+ delete pdResult.updater
266
+ delete pdResult.product
267
+ delete pdResult.domain
268
+
269
+ let pbs: ProductBarcode[]
270
+
271
+ if (productBarcodes) {
272
+ pbs = productBarcodes.map(pb => {
273
+ return {
274
+ ...pb,
275
+ gtin: pb.gtin ? pb.gtin : result.sku,
276
+ product,
277
+ productDetail: pdResult,
278
+ domain,
279
+ creator: user,
280
+ updater: user
281
+ }
282
+ })
283
+ pdResult.productBarcodes = pbs.map(pb => pb.gtin)
284
+ } else {
285
+ pbs = [
286
+ {
287
+ gtin: result.sku,
288
+ product: result,
289
+ productDetail: pdResult,
290
+ domain,
291
+ creator: user,
292
+ updater: user
293
+ }
294
+ ]
295
+ pdResult.productBarcodes = pbs.map(pb => pb.gtin)
296
+ }
297
+
298
+ await tx.getRepository(ProductBarcode).save(pbs)
299
+
300
+ return pdResult
301
+ })
302
+ )
303
+ delete result.creator
304
+ delete result.updater
305
+ delete result.bizplace
306
+ delete result.domain
307
+ response.push({ ...result, productDetails: pds })
308
+ })
309
+ )
310
+ }
311
+
312
+ //set up response body
313
+ context.body = {
314
+ data: response
315
+ }
316
+ })
317
+ } catch (e) {
318
+ if (e instanceof ApiError) ApiErrorHandler(context, e)
319
+ else throwInternalServerError(context, e)
320
+ }
321
+ }
322
+ )