@things-factory/operato-mms 4.3.79-alpha.1 → 4.3.79

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = void 0;
4
4
  const typeorm_1 = require("typeorm");
5
+ const env_1 = require("@things-factory/env");
5
6
  const integration_fulfillment_1 = require("@things-factory/integration-fulfillment");
6
7
  const integration_marketplace_1 = require("@things-factory/integration-marketplace");
7
8
  const marketplace_base_1 = require("@things-factory/marketplace-base");
@@ -69,72 +70,77 @@ exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = {
69
70
  where: { marketplaceStore, category: 'stock_allocation' }
70
71
  });
71
72
  for (let j = 0; j < inventoryProducts.length; j++) {
72
- await (0, typeorm_1.getConnection)().transaction(async (tx) => {
73
- var _a, _b;
74
- const inventoryProduct = inventoryProducts[j];
75
- const marketplaceProductVariations = await tx
76
- .getRepository(marketplace_base_1.MarketplaceProductVariation)
77
- .find({
78
- where: { domain: companyDomain, sku: inventoryProduct.sku },
79
- relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
80
- });
81
- let storeProductVariations = marketplaceProductVariations.filter(productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id);
82
- let percentageValue = 100;
83
- if (storeProductVariations) {
84
- for (let k = 0; k < storeProductVariations.length; k++) {
85
- let storeProductVariation = storeProductVariations[k];
86
- if (marketplaceSetting) {
87
- percentageValue = parseInt(marketplaceSetting.value);
88
- }
89
- let remainQty = Math.floor((inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100));
90
- if (remainQty < 0)
91
- remainQty = 0;
92
- let productVariationLocationId = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.locationId;
93
- let adjustQty = remainQty;
94
- if (marketplaceStore.platform === 'shopify') {
95
- let locationIds = JSON.parse(productVariationLocationId);
96
- adjustQty = adjustQty - storeProductVariation.qty;
97
- if ((_a = locationIds[0]) === null || _a === void 0 ? void 0 : _a.location_id)
98
- productVariationLocationId = locationIds[0].location_id;
99
- }
100
- let validMarketplaceDistributors = [];
101
- if (marketplaceStore.marketplaceDistributors) {
102
- validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(distributor => distributor.status === 'ACTIVE');
73
+ try {
74
+ await (0, typeorm_1.getConnection)().transaction(async (tx) => {
75
+ var _a, _b;
76
+ const inventoryProduct = inventoryProducts[j];
77
+ const marketplaceProductVariations = await tx
78
+ .getRepository(marketplace_base_1.MarketplaceProductVariation)
79
+ .find({
80
+ where: { domain: companyDomain, sku: inventoryProduct.sku },
81
+ relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
82
+ });
83
+ let storeProductVariations = marketplaceProductVariations.filter(productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id);
84
+ let percentageValue = 100;
85
+ if (storeProductVariations) {
86
+ for (let k = 0; k < storeProductVariations.length; k++) {
87
+ let storeProductVariation = storeProductVariations[k];
88
+ if (marketplaceSetting) {
89
+ percentageValue = parseInt(marketplaceSetting.value);
90
+ }
91
+ let remainQty = Math.floor((inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100));
92
+ if (remainQty < 0)
93
+ remainQty = 0;
94
+ let productVariationLocationId = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.locationId;
95
+ let adjustQty = remainQty;
96
+ if (marketplaceStore.platform === 'shopify') {
97
+ let locationIds = JSON.parse(productVariationLocationId);
98
+ adjustQty = adjustQty - storeProductVariation.qty;
99
+ if ((_a = locationIds[0]) === null || _a === void 0 ? void 0 : _a.location_id)
100
+ productVariationLocationId = locationIds[0].location_id;
101
+ }
102
+ let validMarketplaceDistributors = [];
103
+ if (marketplaceStore.marketplaceDistributors) {
104
+ validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(distributor => distributor.status === 'ACTIVE');
105
+ }
106
+ const hasVariation = (_b = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.marketplaceProduct) === null || _b === void 0 ? void 0 : _b.hasVariation;
107
+ if (hasVariation) {
108
+ await integration_marketplace_1.StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
109
+ {
110
+ itemId: storeProductVariation.marketplaceProduct.itemId,
111
+ variationId: storeProductVariation.variationId,
112
+ variationSku: storeProductVariation.variationSku,
113
+ qty: adjustQty,
114
+ locationId: productVariationLocationId,
115
+ inventoryItemId: storeProductVariation.inventoryItemId,
116
+ distributors: validMarketplaceDistributors
117
+ }
118
+ ]);
119
+ }
120
+ else {
121
+ await integration_marketplace_1.StoreAPI.updateStoreProductStock(marketplaceStore, [
122
+ {
123
+ itemId: storeProductVariation.marketplaceProduct.itemId,
124
+ variationId: storeProductVariation.variationId,
125
+ variationSku: storeProductVariation.variationSku,
126
+ qty: adjustQty,
127
+ distributors: validMarketplaceDistributors
128
+ }
129
+ ]);
130
+ }
131
+ storeProductVariation.qty = remainQty;
132
+ await tx.getRepository(marketplace_base_1.MarketplaceProductVariation).save(storeProductVariation);
103
133
  }
104
- const hasVariation = (_b = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.marketplaceProduct) === null || _b === void 0 ? void 0 : _b.hasVariation;
105
- if (hasVariation) {
106
- await integration_marketplace_1.StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
107
- {
108
- itemId: storeProductVariation.marketplaceProduct.itemId,
109
- variationId: storeProductVariation.variationId,
110
- variationSku: storeProductVariation.variationSku,
111
- qty: adjustQty,
112
- locationId: productVariationLocationId,
113
- inventoryItemId: storeProductVariation.inventoryItemId,
114
- distributors: validMarketplaceDistributors
115
- }
116
- ]);
117
- }
118
- else {
119
- await integration_marketplace_1.StoreAPI.updateStoreProductStock(marketplaceStore, [
120
- {
121
- itemId: storeProductVariation.marketplaceProduct.itemId,
122
- variationId: storeProductVariation.variationId,
123
- variationSku: storeProductVariation.variationSku,
124
- qty: adjustQty,
125
- distributors: validMarketplaceDistributors
126
- }
127
- ]);
128
- }
129
- storeProductVariation.qty = remainQty;
130
- await tx.getRepository(marketplace_base_1.MarketplaceProductVariation).save(storeProductVariation);
131
134
  }
132
- }
133
- });
135
+ });
136
+ }
137
+ catch (error) {
138
+ env_1.logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`);
139
+ }
134
140
  }
135
141
  }
136
142
  catch (e) {
137
- console.log(e);
143
+ env_1.logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`);
138
144
  }
139
145
  }
140
146
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"auto-update-all-marketplace-product-variation-quantity.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAEtD,qFAAwE;AACxE,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAqE;AACrE,iDAA8C;AAC9C,mEAAsH;AAEzG,QAAA,wDAAwD,GAAG;IACtE,KAAK,CAAC,gDAAgD,CAAC,CAAM,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE,EAAE,OAAY;QAC3G,MAAM,aAAa,GAAW,MAAM,IAAA,uBAAa,EAAC,cAAM,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QAElF,MAAM,iBAAiB,GAAuB,MAAM,IAAA,uBAAa,EAAC,0CAAgB,CAAC,CAAC,IAAI,CAAC;YACvF,KAAK,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE;YAClD,SAAS,EAAE,CAAC,yBAAyB,CAAC;SACvC,CAAC,CAAA;QAEF,MAAM,gBAAgB,GAAG,MAAM,wCAAc,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAA;QAC/E,MAAM,QAAQ,GAAW,gBAAgB,CAAC,QAAQ,CAAA;Q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ACH;qCAAM;oCACL,MAAM,kCAAQ,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;wCACvD;4CACE,MAAM,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,MAAM;4CACvD,WAAW,EAAE,qBAAqB,CAAC,WAAW;4CAC9C,YAAY,EAAE,qBAAqB,CAAC,YAAY;4CAChD,GAAG,EAAE,SAAS;4CACd,YAAY,EAAE,4BAA4B;yCAC3C;qCACF,CAAC,CAAA;iCACH;gCAED,qBAAqB,CAAC,GAAG,GAAG,SAAS,CAAA;gCACrC,MAAM,EAAE,CAAC,aAAa,CAAC,8CAA2B,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;6BAChF;yBACF;oBACH,CAAC,CAAC,CAAA;iBACH;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;aACf;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
1
+ {"version":3,"file":"auto-update-all-marketplace-product-variation-quantity.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAEtD,6CAA4C;AAC5C,qFAAwE;AACxE,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAqE;AACrE,iDAA8C;AAC9C,mEAAsH;AAEzG,QAAA,wDAAwD,GAAG;IACtE,KAAK,CAAC,gDAAgD,CAAC,CAAM,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE,EAAE,OAAY;QAC3G,MAAM,aAAa,GAAW,MAAM,IAAA,uBAAa,EAAC,cAAM,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QAElF,MAAM,iBAAiB,GAAuB,MAAM,IAAA,uBAAa,EAAC,0CAAgB,CAAC,CAAC,IAAI,CAAC;YACvF,KAAK,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE;YACl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AC,WAAW;gDAC9C,YAAY,EAAE,qBAAqB,CAAC,YAAY;gDAChD,GAAG,EAAE,SAAS;gDACd,UAAU,EAAE,0BAA0B;gDACtC,eAAe,EAAE,qBAAqB,CAAC,eAAe;gDACtD,YAAY,EAAE,4BAA4B;6CAC3C;yCACF,CAAC,CAAA;qCACH;yCAAM;wCACL,MAAM,kCAAQ,CAAC,uBAAuB,CAAC,gBAAgB,EAAE;4CACvD;gDACE,MAAM,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,MAAM;gDACvD,WAAW,EAAE,qBAAqB,CAAC,WAAW;gDAC9C,YAAY,EAAE,qBAAqB,CAAC,YAAY;gDAChD,GAAG,EAAE,SAAS;gDACd,YAAY,EAAE,4BAA4B;6CAC3C;yCACF,CAAC,CAAA;qCACH;oCAED,qBAAqB,CAAC,GAAG,GAAG,SAAS,CAAA;oCACrC,MAAM,EAAE,CAAC,aAAa,CAAC,8CAA2B,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;iCAChF;6BACF;wBACH,CAAC,CAAC,CAAA;qBACH;oBAAC,OAAO,KAAK,EAAE;wBACd,YAAM,CAAC,KAAK,CACV,0FAA0F,KAAK,EAAE,CAClG,CAAA;qBACF;iBACF;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,YAAM,CAAC,KAAK,CAAC,0FAA0F,CAAC,EAAE,CAAC,CAAA;aAC5G;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/operato-mms",
3
- "version": "4.3.79-alpha.1",
3
+ "version": "4.3.79",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -60,50 +60,50 @@
60
60
  "@operato/scene-table": "^0.1.8",
61
61
  "@operato/scene-timer": "^0.1.8",
62
62
  "@operato/scene-wheel-sorter": "^0.1.8",
63
- "@things-factory/apptool-ui": "^4.3.79-alpha.0",
64
- "@things-factory/attachment-base": "^4.3.79-alpha.0",
65
- "@things-factory/auth-ui": "^4.3.79-alpha.0",
66
- "@things-factory/biz-base": "^4.3.79-alpha.0",
67
- "@things-factory/board-service": "^4.3.79-alpha.0",
68
- "@things-factory/board-ui": "^4.3.79-alpha.0",
69
- "@things-factory/code-ui": "^4.3.79-alpha.0",
70
- "@things-factory/context-ui": "^4.3.79-alpha.0",
71
- "@things-factory/dashboard": "^4.3.79-alpha.0",
72
- "@things-factory/export-ui": "^4.3.79-alpha.0",
73
- "@things-factory/export-ui-csv": "^4.3.79-alpha.0",
74
- "@things-factory/export-ui-excel": "^4.3.79-alpha.0",
75
- "@things-factory/geography": "^4.3.79-alpha.0",
76
- "@things-factory/grist-ui": "^4.3.79-alpha.0",
77
- "@things-factory/help": "^4.3.79-alpha.0",
78
- "@things-factory/i18n-base": "^4.3.79-alpha.0",
79
- "@things-factory/integration-fulfillment": "^4.3.79-alpha.0",
80
- "@things-factory/integration-lmd": "^4.3.79-alpha.0",
81
- "@things-factory/lite-menu": "^4.3.79-alpha.0",
82
- "@things-factory/marketplace-base": "^4.3.79-alpha.1",
83
- "@things-factory/more-ui": "^4.3.79-alpha.0",
84
- "@things-factory/notification": "^4.3.79-alpha.0",
85
- "@things-factory/oauth2-client": "^4.3.79-alpha.0",
86
- "@things-factory/pdf": "^4.3.79-alpha.0",
87
- "@things-factory/product-base": "^4.3.79-alpha.0",
88
- "@things-factory/resource-ui": "^4.3.79-alpha.0",
89
- "@things-factory/scene-data-transform": "^4.3.79-alpha.0",
90
- "@things-factory/scene-excel": "^4.3.79-alpha.0",
91
- "@things-factory/scene-firebase": "^4.3.79-alpha.0",
92
- "@things-factory/scene-form": "^4.3.79-alpha.0",
93
- "@things-factory/scene-google-map": "^4.3.79-alpha.0",
94
- "@things-factory/scene-graphql": "^4.3.79-alpha.0",
95
- "@things-factory/scene-label": "^4.3.79-alpha.0",
96
- "@things-factory/scene-marker": "^4.3.79-alpha.0",
97
- "@things-factory/scene-mqtt": "^4.3.79-alpha.0",
98
- "@things-factory/scene-restful": "^4.3.79-alpha.0",
99
- "@things-factory/scene-visualizer": "^4.3.79-alpha.0",
100
- "@things-factory/setting-ui": "^4.3.79-alpha.0",
101
- "@things-factory/system-ui": "^4.3.79-alpha.0",
102
- "@things-factory/warehouse-base": "^4.3.79-alpha.1"
63
+ "@things-factory/apptool-ui": "^4.3.78",
64
+ "@things-factory/attachment-base": "^4.3.78",
65
+ "@things-factory/auth-ui": "^4.3.78",
66
+ "@things-factory/biz-base": "^4.3.78",
67
+ "@things-factory/board-service": "^4.3.78",
68
+ "@things-factory/board-ui": "^4.3.78",
69
+ "@things-factory/code-ui": "^4.3.78",
70
+ "@things-factory/context-ui": "^4.3.78",
71
+ "@things-factory/dashboard": "^4.3.78",
72
+ "@things-factory/export-ui": "^4.3.78",
73
+ "@things-factory/export-ui-csv": "^4.3.78",
74
+ "@things-factory/export-ui-excel": "^4.3.78",
75
+ "@things-factory/geography": "^4.3.78",
76
+ "@things-factory/grist-ui": "^4.3.78",
77
+ "@things-factory/help": "^4.3.78",
78
+ "@things-factory/i18n-base": "^4.3.78",
79
+ "@things-factory/integration-fulfillment": "^4.3.78",
80
+ "@things-factory/integration-lmd": "^4.3.78",
81
+ "@things-factory/lite-menu": "^4.3.78",
82
+ "@things-factory/marketplace-base": "^4.3.78",
83
+ "@things-factory/more-ui": "^4.3.78",
84
+ "@things-factory/notification": "^4.3.78",
85
+ "@things-factory/oauth2-client": "^4.3.78",
86
+ "@things-factory/pdf": "^4.3.74",
87
+ "@things-factory/product-base": "^4.3.78",
88
+ "@things-factory/resource-ui": "^4.3.78",
89
+ "@things-factory/scene-data-transform": "^4.3.76",
90
+ "@things-factory/scene-excel": "^4.3.76",
91
+ "@things-factory/scene-firebase": "^4.3.76",
92
+ "@things-factory/scene-form": "^4.3.76",
93
+ "@things-factory/scene-google-map": "^4.3.76",
94
+ "@things-factory/scene-graphql": "^4.3.76",
95
+ "@things-factory/scene-label": "^4.3.78",
96
+ "@things-factory/scene-marker": "^4.3.76",
97
+ "@things-factory/scene-mqtt": "^4.3.76",
98
+ "@things-factory/scene-restful": "^4.3.76",
99
+ "@things-factory/scene-visualizer": "^4.3.76",
100
+ "@things-factory/setting-ui": "^4.3.78",
101
+ "@things-factory/system-ui": "^4.3.78",
102
+ "@things-factory/warehouse-base": "^4.3.79"
103
103
  },
104
104
  "devDependencies": {
105
- "@things-factory/builder": "^4.3.79-alpha.0",
105
+ "@things-factory/builder": "^4.3.74",
106
106
  "@types/node-fetch": "^2.5.7"
107
107
  },
108
- "gitHead": "781aa433ce81cb1cd08d6a3c4abb2934f0a192c1"
108
+ "gitHead": "e1d319473973c800e4605cc6c47836b9a328c71b"
109
109
  }
@@ -1,5 +1,6 @@
1
1
  import { getConnection, getRepository } from 'typeorm'
2
2
 
3
+ import { logger } from '@things-factory/env'
3
4
  import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
4
5
  import { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
5
6
  import { MarketplaceProductVariation } from '@things-factory/marketplace-base'
@@ -89,82 +90,88 @@ export const autoUpdateAllMarketplaceProductVariationQuantityResolver = {
89
90
  })
90
91
 
91
92
  for (let j = 0; j < inventoryProducts.length; j++) {
92
- await getConnection().transaction(async tx => {
93
- const inventoryProduct = inventoryProducts[j]
94
- const marketplaceProductVariations: MarketplaceProductVariation[] = await tx
95
- .getRepository(MarketplaceProductVariation)
96
- .find({
97
- where: { domain: companyDomain, sku: inventoryProduct.sku },
98
- relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
99
- })
100
-
101
- let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(
102
- productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id
103
- )
104
-
105
- let percentageValue: number = 100
106
- if (storeProductVariations) {
107
- for (let k = 0; k < storeProductVariations.length; k++) {
108
- let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]
109
- if (marketplaceSetting) {
110
- percentageValue = parseInt(marketplaceSetting.value)
111
- }
112
-
113
- let remainQty: number = Math.floor(
114
- (inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)
115
- )
116
- if (remainQty < 0) remainQty = 0
117
-
118
- let productVariationLocationId = storeProductVariation?.locationId
119
- let adjustQty: number = remainQty
120
-
121
- if (marketplaceStore.platform === 'shopify') {
122
- let locationIds: any[] = JSON.parse(productVariationLocationId)
123
- adjustQty = adjustQty - storeProductVariation.qty
124
- if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
125
- }
126
-
127
- let validMarketplaceDistributors: any[] = []
128
- if (marketplaceStore.marketplaceDistributors) {
129
- validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
130
- distributor => distributor.status === 'ACTIVE'
93
+ try {
94
+ await getConnection().transaction(async tx => {
95
+ const inventoryProduct = inventoryProducts[j]
96
+ const marketplaceProductVariations: MarketplaceProductVariation[] = await tx
97
+ .getRepository(MarketplaceProductVariation)
98
+ .find({
99
+ where: { domain: companyDomain, sku: inventoryProduct.sku },
100
+ relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
101
+ })
102
+
103
+ let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(
104
+ productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id
105
+ )
106
+
107
+ let percentageValue: number = 100
108
+ if (storeProductVariations) {
109
+ for (let k = 0; k < storeProductVariations.length; k++) {
110
+ let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]
111
+ if (marketplaceSetting) {
112
+ percentageValue = parseInt(marketplaceSetting.value)
113
+ }
114
+
115
+ let remainQty: number = Math.floor(
116
+ (inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)
131
117
  )
118
+ if (remainQty < 0) remainQty = 0
119
+
120
+ let productVariationLocationId = storeProductVariation?.locationId
121
+ let adjustQty: number = remainQty
122
+
123
+ if (marketplaceStore.platform === 'shopify') {
124
+ let locationIds: any[] = JSON.parse(productVariationLocationId)
125
+ adjustQty = adjustQty - storeProductVariation.qty
126
+ if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
127
+ }
128
+
129
+ let validMarketplaceDistributors: any[] = []
130
+ if (marketplaceStore.marketplaceDistributors) {
131
+ validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
132
+ distributor => distributor.status === 'ACTIVE'
133
+ )
134
+ }
135
+
136
+ const hasVariation: boolean = storeProductVariation?.marketplaceProduct?.hasVariation
137
+
138
+ if (hasVariation) {
139
+ await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
140
+ {
141
+ itemId: storeProductVariation.marketplaceProduct.itemId,
142
+ variationId: storeProductVariation.variationId,
143
+ variationSku: storeProductVariation.variationSku,
144
+ qty: adjustQty,
145
+ locationId: productVariationLocationId,
146
+ inventoryItemId: storeProductVariation.inventoryItemId,
147
+ distributors: validMarketplaceDistributors
148
+ }
149
+ ])
150
+ } else {
151
+ await StoreAPI.updateStoreProductStock(marketplaceStore, [
152
+ {
153
+ itemId: storeProductVariation.marketplaceProduct.itemId,
154
+ variationId: storeProductVariation.variationId,
155
+ variationSku: storeProductVariation.variationSku,
156
+ qty: adjustQty,
157
+ distributors: validMarketplaceDistributors
158
+ }
159
+ ])
160
+ }
161
+
162
+ storeProductVariation.qty = remainQty
163
+ await tx.getRepository(MarketplaceProductVariation).save(storeProductVariation)
132
164
  }
133
-
134
- const hasVariation: boolean = storeProductVariation?.marketplaceProduct?.hasVariation
135
-
136
- if (hasVariation) {
137
- await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
138
- {
139
- itemId: storeProductVariation.marketplaceProduct.itemId,
140
- variationId: storeProductVariation.variationId,
141
- variationSku: storeProductVariation.variationSku,
142
- qty: adjustQty,
143
- locationId: productVariationLocationId,
144
- inventoryItemId: storeProductVariation.inventoryItemId,
145
- distributors: validMarketplaceDistributors
146
- }
147
- ])
148
- } else {
149
- await StoreAPI.updateStoreProductStock(marketplaceStore, [
150
- {
151
- itemId: storeProductVariation.marketplaceProduct.itemId,
152
- variationId: storeProductVariation.variationId,
153
- variationSku: storeProductVariation.variationSku,
154
- qty: adjustQty,
155
- distributors: validMarketplaceDistributors
156
- }
157
- ])
158
- }
159
-
160
- storeProductVariation.qty = remainQty
161
- await tx.getRepository(MarketplaceProductVariation).save(storeProductVariation)
162
165
  }
163
- }
164
- })
166
+ })
167
+ } catch (error) {
168
+ logger.error(
169
+ `interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`
170
+ )
171
+ }
165
172
  }
166
173
  } catch (e) {
167
- console.log(e)
174
+ logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`)
168
175
  }
169
176
  }
170
177