@things-factory/operato-hub 4.3.80-alpha.2 → 4.3.80-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.
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = void 0;
4
+ const typeorm_1 = require("typeorm");
5
+ const env_1 = require("@things-factory/env");
6
+ const integration_fulfillment_1 = require("@things-factory/integration-fulfillment");
7
+ const integration_marketplace_1 = require("@things-factory/integration-marketplace");
8
+ const marketplace_base_1 = require("@things-factory/marketplace-base");
9
+ const product_base_1 = require("@things-factory/product-base");
10
+ const shell_1 = require("@things-factory/shell");
11
+ const warehouse_base_1 = require("@things-factory/warehouse-base");
12
+ exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = {
13
+ async autoUpdateAllMarketplaceProductVariationQuantity(_, { companyDomainId, warehouseId }, context) {
14
+ const companyDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(companyDomainId);
15
+ const marketplaceStores = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceStore).find({
16
+ where: { domain: companyDomain, status: 'ACTIVE' },
17
+ relations: ['marketplaceDistributors']
18
+ });
19
+ const fulfilmentCenter = await integration_fulfillment_1.FulfillmentAPI.getFulfillmentCenter(warehouseId);
20
+ const centerId = fulfilmentCenter.centerId;
21
+ const warehouseDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne({ where: { subdomain: centerId } });
22
+ let products = await (0, typeorm_1.getRepository)(product_base_1.Product).find({
23
+ where: { domain: companyDomain },
24
+ relations: ['productDetails']
25
+ });
26
+ let inventoryProducts = await Promise.all(products.map(async (product) => {
27
+ const productDetails = product.productDetails;
28
+ const defaultProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0];
29
+ let qb = await (0, typeorm_1.getRepository)(warehouse_base_1.Inventory).createQueryBuilder('inv');
30
+ qb.leftJoinAndSelect('inv.location', 'loc')
31
+ .andWhere('"inv"."domain_id" = :domainId')
32
+ .andWhere('"inv"."product_id" = :productId')
33
+ .andWhere('"inv"."status" != :status')
34
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
35
+ .setParameters({
36
+ domainId: warehouseDomain.id,
37
+ productId: product.id,
38
+ status: warehouse_base_1.INVENTORY_STATUS.TERMINATED,
39
+ locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
40
+ });
41
+ let inventories = await qb.getMany();
42
+ const inventoryQty = inventories.reduce((total, currentValue) => {
43
+ total += currentValue.qty;
44
+ return total;
45
+ }, 0);
46
+ const inventoryLockedQty = inventories.reduce((total, currentValue) => {
47
+ total += currentValue.lockedQty;
48
+ return total;
49
+ }, 0);
50
+ return {
51
+ product,
52
+ sku: product.sku,
53
+ name: product.name,
54
+ packingType: defaultProductDetail.packingType,
55
+ packingSize: defaultProductDetail.packingSize,
56
+ uom: defaultProductDetail.uom,
57
+ qty: inventoryQty - inventoryLockedQty
58
+ };
59
+ }));
60
+ await (0, typeorm_1.getConnection)().transaction(async (tx) => {
61
+ let bundleProductInventories = await (0, warehouse_base_1.getProductBundleInventory)(warehouseDomain, companyDomain, inventoryProducts, tx);
62
+ bundleProductInventories.map(bundleProductInventory => {
63
+ inventoryProducts.push(bundleProductInventory);
64
+ });
65
+ });
66
+ for (let i = 0; i < marketplaceStores.length; i++) {
67
+ try {
68
+ const marketplaceStore = marketplaceStores[i];
69
+ const marketplaceSetting = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceSetting).findOne({
70
+ where: { marketplaceStore, category: 'stock_allocation' }
71
+ });
72
+ for (let j = 0; j < inventoryProducts.length; j++) {
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);
133
+ }
134
+ }
135
+ });
136
+ }
137
+ catch (error) {
138
+ env_1.logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`);
139
+ }
140
+ }
141
+ }
142
+ catch (e) {
143
+ env_1.logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`);
144
+ }
145
+ }
146
+ return true;
147
+ }
148
+ };
149
+ //# sourceMappingURL=auto-update-all-marketplace-product-variation-quantity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-update-all-marketplace-product-variation-quantity.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/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,aAA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,MAAM;gDACvD,WAAW,EAAE,qBAAqB,CAAC,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"}
@@ -10,6 +10,7 @@ const sync_products_from_account_1 = require("./sync-products-from-account");
10
10
  const sync_products_to_account_1 = require("./sync-products-to-account");
11
11
  const sync_products_to_sellercraft_1 = require("./sync-products-to-sellercraft");
12
12
  const create_dat_shipments_1 = require("./create-dat-shipments");
13
+ const auto_update_all_marketplace_product_variation_quantity_1 = require("./auto-update-all-marketplace-product-variation-quantity");
13
14
  exports.Query = Object.assign(Object.assign(Object.assign({}, fetch_sync_products_1.fetchSyncProductsResolver), fetch_sync_purchase_orders_1.fetchSyncPurchaseOrdersResolver), fetch_sync_invoices_1.fetchSyncInvoicesResolver);
14
- exports.Mutation = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, sync_products_to_sellercraft_1.syncProductsToSellercraftResolver), sync_products_from_account_1.syncProductsFromAccountResolver), sync_products_to_account_1.syncProductsToAccountResolver), sync_all_products_to_sellercraft_1.syncAllProductsToSellercraftResolver), sellercraft_pack_marketplace_order_1.sellercraftPackMarketplaceOrderResolver), create_dat_shipments_1.createDatShipments);
15
+ exports.Mutation = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, sync_products_to_sellercraft_1.syncProductsToSellercraftResolver), sync_products_from_account_1.syncProductsFromAccountResolver), sync_products_to_account_1.syncProductsToAccountResolver), sync_all_products_to_sellercraft_1.syncAllProductsToSellercraftResolver), sellercraft_pack_marketplace_order_1.sellercraftPackMarketplaceOrderResolver), create_dat_shipments_1.createDatShipments), auto_update_all_marketplace_product_variation_quantity_1.autoUpdateAllMarketplaceProductVariationQuantityResolver);
15
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/index.ts"],"names":[],"mappings":";;;AAAA,+DAAiE;AACjE,+DAAiE;AACjE,6EAA8E;AAC9E,6FAA8F;AAC9F,yFAAyF;AACzF,6EAA8E;AAC9E,yEAA0E;AAC1E,iFAAkF;AAClF,iEAA2D;AAE9C,QAAA,KAAK,iDACb,+CAAyB,GACzB,4DAA+B,GAC/B,+CAAyB,EAC7B;AAEY,QAAA,QAAQ,2FAChB,gEAAiC,GACjC,4DAA+B,GAC/B,wDAA6B,GAC7B,uEAAoC,GACpC,4EAAuC,GACvC,yCAAkB,EACtB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/index.ts"],"names":[],"mappings":";;;AAAA,+DAAiE;AACjE,+DAAiE;AACjE,6EAA8E;AAC9E,6FAA8F;AAC9F,yFAAyF;AACzF,6EAA8E;AAC9E,yEAA0E;AAC1E,iFAAkF;AAClF,iEAA2D;AAC3D,qIAAmI;AAEtH,QAAA,KAAK,iDACb,+CAAyB,GACzB,4DAA+B,GAC/B,+CAAyB,EAC7B;AAEY,QAAA,QAAQ,yGAChB,gEAAiC,GACjC,4DAA+B,GAC/B,wDAA6B,GAC7B,uEAAoC,GACpC,4EAAuC,GACvC,yCAAkB,GAClB,iHAAwD,EAC5D"}
@@ -19,6 +19,7 @@ exports.Mutation = `
19
19
  syncAllProductsToSellercraft: Boolean @transaction
20
20
  sellercraftPackMarketplaceOrder: Boolean @transaction
21
21
  createDatShipments: Boolean @transaction
22
+ autoUpdateAllMarketplaceProductVariationQuantity(companyDomainId: String, warehouseId: String): Boolean @transaction
22
23
  `;
23
24
  exports.Types = [
24
25
  sync_product_set_1.SyncProductSet,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/synchronization/index.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AACrD,yDAAoE;AACpE,2DAAqD;AACrD,yDAAmD;AACnD,yEAAkE;AAClE,uEAAiF;AAEpE,QAAA,KAAK,GAAiB;;;;CAIlC,CAAA;AAEY,QAAA,QAAQ,GAAiB;;;;;;;CAOrC,CAAA;AAEY,QAAA,KAAK,GAAG;IACnB,iCAAc;IACd,mCAAe;IACf,8CAAoB;IACpB,gDAAqB;IACrB,GAAG,+BAAM;IACT,iCAAc;IACd,mCAAe;IACf,GAAG,wBAAM;CACV,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/synchronization/index.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AACrD,yDAAoE;AACpE,2DAAqD;AACrD,yDAAmD;AACnD,yEAAkE;AAClE,uEAAiF;AAEpE,QAAA,KAAK,GAAiB;;;;CAIlC,CAAA;AAEY,QAAA,QAAQ,GAAiB;;;;;;;;CAQrC,CAAA;AAEY,QAAA,KAAK,GAAG;IACnB,iCAAc;IACd,mCAAe;IACf,8CAAoB;IACpB,gDAAqB;IACrB,GAAG,+BAAM;IACT,iCAAc;IACd,mCAAe;IACf,GAAG,wBAAM;CACV,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/operato-hub",
3
- "version": "4.3.80-alpha.2",
3
+ "version": "4.3.80-alpha.3",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -56,66 +56,66 @@
56
56
  "@operato/scene-tab": "^0.1.8",
57
57
  "@operato/scene-table": "^0.1.8",
58
58
  "@operato/scene-wheel-sorter": "^0.1.8",
59
- "@things-factory/api": "^4.3.79-alpha.0",
60
- "@things-factory/apptool-ui": "^4.3.79-alpha.0",
61
- "@things-factory/attachment-base": "^4.3.79-alpha.0",
62
- "@things-factory/auth-base": "^4.3.79-alpha.0",
63
- "@things-factory/auth-ui": "^4.3.79-alpha.0",
64
- "@things-factory/biz-base": "^4.3.79-alpha.0",
65
- "@things-factory/biz-ui": "^4.3.79-alpha.0",
66
- "@things-factory/board-service": "^4.3.79-alpha.0",
67
- "@things-factory/board-ui": "^4.3.79-alpha.0",
68
- "@things-factory/code-ui": "^4.3.79-alpha.0",
69
- "@things-factory/component-ui": "^4.3.79-alpha.0",
70
- "@things-factory/context-ui": "^4.3.79-alpha.0",
71
- "@things-factory/document-template-ui": "^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/grist-ui": "^4.3.79-alpha.0",
76
- "@things-factory/help": "^4.3.79-alpha.0",
77
- "@things-factory/i18n-base": "^4.3.79-alpha.0",
78
- "@things-factory/import-ui": "^4.3.79-alpha.0",
79
- "@things-factory/import-ui-excel": "^4.3.79-alpha.0",
80
- "@things-factory/integration-accounting": "^4.3.80-alpha.1",
81
- "@things-factory/integration-fulfillment": "^4.3.79-alpha.0",
82
- "@things-factory/integration-lmd": "^4.3.79-alpha.0",
83
- "@things-factory/integration-marketplace": "^4.3.79-alpha.0",
84
- "@things-factory/integration-pos": "^4.3.79-alpha.0",
85
- "@things-factory/integration-sellercraft": "^4.3.79-alpha.0",
86
- "@things-factory/integration-sftp": "^4.3.79-alpha.0",
87
- "@things-factory/lite-menu": "^4.3.79-alpha.0",
88
- "@things-factory/more-ui": "^4.3.79-alpha.0",
89
- "@things-factory/notification": "^4.3.79-alpha.0",
90
- "@things-factory/pdf": "^4.3.79-alpha.0",
91
- "@things-factory/product-ui": "^4.3.80-alpha.1",
92
- "@things-factory/resource-ui": "^4.3.79-alpha.0",
93
- "@things-factory/sales-base": "^4.3.80-alpha.1",
94
- "@things-factory/scene-data-transform": "^4.3.79-alpha.0",
95
- "@things-factory/scene-excel": "^4.3.79-alpha.0",
96
- "@things-factory/scene-firebase": "^4.3.79-alpha.0",
97
- "@things-factory/scene-form": "^4.3.79-alpha.0",
98
- "@things-factory/scene-google-map": "^4.3.79-alpha.0",
99
- "@things-factory/scene-graphql": "^4.3.79-alpha.0",
100
- "@things-factory/scene-label": "^4.3.79-alpha.0",
101
- "@things-factory/scene-marker": "^4.3.79-alpha.0",
102
- "@things-factory/scene-mqtt": "^4.3.79-alpha.0",
103
- "@things-factory/scene-restful": "^4.3.79-alpha.0",
104
- "@things-factory/scene-visualizer": "^4.3.79-alpha.0",
105
- "@things-factory/setting-ui": "^4.3.79-alpha.0",
106
- "@things-factory/shell": "^4.3.79-alpha.0",
107
- "@things-factory/system-ui": "^4.3.79-alpha.0",
108
- "@things-factory/warehouse-base": "^4.3.80-alpha.1",
109
- "@things-factory/worksheet-base": "^4.3.80-alpha.1",
59
+ "@things-factory/api": "^4.3.78",
60
+ "@things-factory/apptool-ui": "^4.3.78",
61
+ "@things-factory/attachment-base": "^4.3.78",
62
+ "@things-factory/auth-base": "^4.3.78",
63
+ "@things-factory/auth-ui": "^4.3.78",
64
+ "@things-factory/biz-base": "^4.3.78",
65
+ "@things-factory/biz-ui": "^4.3.78",
66
+ "@things-factory/board-service": "^4.3.78",
67
+ "@things-factory/board-ui": "^4.3.78",
68
+ "@things-factory/code-ui": "^4.3.78",
69
+ "@things-factory/component-ui": "^4.3.74",
70
+ "@things-factory/context-ui": "^4.3.78",
71
+ "@things-factory/document-template-ui": "^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/grist-ui": "^4.3.78",
76
+ "@things-factory/help": "^4.3.78",
77
+ "@things-factory/i18n-base": "^4.3.78",
78
+ "@things-factory/import-ui": "^4.3.78",
79
+ "@things-factory/import-ui-excel": "^4.3.78",
80
+ "@things-factory/integration-accounting": "^4.3.78",
81
+ "@things-factory/integration-fulfillment": "^4.3.78",
82
+ "@things-factory/integration-lmd": "^4.3.78",
83
+ "@things-factory/integration-marketplace": "^4.3.78",
84
+ "@things-factory/integration-pos": "^4.3.78",
85
+ "@things-factory/integration-sellercraft": "^4.3.79",
86
+ "@things-factory/integration-sftp": "^4.3.78",
87
+ "@things-factory/lite-menu": "^4.3.78",
88
+ "@things-factory/more-ui": "^4.3.78",
89
+ "@things-factory/notification": "^4.3.78",
90
+ "@things-factory/pdf": "^4.3.74",
91
+ "@things-factory/product-ui": "^4.3.78",
92
+ "@things-factory/resource-ui": "^4.3.78",
93
+ "@things-factory/sales-base": "^4.3.81",
94
+ "@things-factory/scene-data-transform": "^4.3.76",
95
+ "@things-factory/scene-excel": "^4.3.76",
96
+ "@things-factory/scene-firebase": "^4.3.76",
97
+ "@things-factory/scene-form": "^4.3.76",
98
+ "@things-factory/scene-google-map": "^4.3.76",
99
+ "@things-factory/scene-graphql": "^4.3.76",
100
+ "@things-factory/scene-label": "^4.3.80-alpha.3",
101
+ "@things-factory/scene-marker": "^4.3.76",
102
+ "@things-factory/scene-mqtt": "^4.3.76",
103
+ "@things-factory/scene-restful": "^4.3.76",
104
+ "@things-factory/scene-visualizer": "^4.3.76",
105
+ "@things-factory/setting-ui": "^4.3.78",
106
+ "@things-factory/shell": "^4.3.80-alpha.3",
107
+ "@things-factory/system-ui": "^4.3.78",
108
+ "@things-factory/warehouse-base": "^4.3.81",
109
+ "@things-factory/worksheet-base": "^4.3.81",
110
110
  "koa2-swagger-ui": "^5.0.2",
111
111
  "swagger-jsdoc": "^5.0.0",
112
112
  "yamljs": "^0.3.0"
113
113
  },
114
114
  "devDependencies": {
115
- "@things-factory/builder": "^4.3.79-alpha.0"
115
+ "@things-factory/builder": "^4.3.80-alpha.3"
116
116
  },
117
117
  "resolutions": {
118
118
  "core-js": "^3.16.0"
119
119
  },
120
- "gitHead": "bb18947c21ab30207b10212b9f40ab887d8ee160"
120
+ "gitHead": "c50b741687aa9260a1f9b46ed125737aed989df6"
121
121
  }
@@ -0,0 +1,180 @@
1
+ import { getConnection, getRepository } from 'typeorm'
2
+
3
+ import { logger } from '@things-factory/env'
4
+ import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
5
+ import { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
6
+ import { MarketplaceProductVariation } from '@things-factory/marketplace-base'
7
+ import { Product, ProductDetail } from '@things-factory/product-base'
8
+ import { Domain } from '@things-factory/shell'
9
+ import { getProductBundleInventory, Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
10
+
11
+ export const autoUpdateAllMarketplaceProductVariationQuantityResolver = {
12
+ async autoUpdateAllMarketplaceProductVariationQuantity(_: any, { companyDomainId, warehouseId }, context: any) {
13
+ const companyDomain: Domain = await getRepository(Domain).findOne(companyDomainId)
14
+
15
+ const marketplaceStores: MarketplaceStore[] = await getRepository(MarketplaceStore).find({
16
+ where: { domain: companyDomain, status: 'ACTIVE' },
17
+ relations: ['marketplaceDistributors']
18
+ })
19
+
20
+ const fulfilmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
21
+ const centerId: string = fulfilmentCenter.centerId
22
+ const warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })
23
+
24
+ let products: Product[] = await getRepository(Product).find({
25
+ where: { domain: companyDomain },
26
+ relations: ['productDetails']
27
+ })
28
+
29
+ let inventoryProducts: any[] = await Promise.all(
30
+ products.map(async product => {
31
+ const productDetails: ProductDetail[] = product.productDetails
32
+ const defaultProductDetail: ProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0]
33
+
34
+ let qb = await getRepository(Inventory).createQueryBuilder('inv')
35
+ qb.leftJoinAndSelect('inv.location', 'loc')
36
+ .andWhere('"inv"."domain_id" = :domainId')
37
+ .andWhere('"inv"."product_id" = :productId')
38
+ .andWhere('"inv"."status" != :status')
39
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
40
+ .setParameters({
41
+ domainId: warehouseDomain.id,
42
+ productId: product.id,
43
+ status: INVENTORY_STATUS.TERMINATED,
44
+ locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
45
+ })
46
+
47
+ let inventories: Inventory[] = await qb.getMany()
48
+
49
+ const inventoryQty: number = inventories.reduce((total, currentValue) => {
50
+ total += currentValue.qty
51
+ return total
52
+ }, 0)
53
+
54
+ const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {
55
+ total += currentValue.lockedQty
56
+ return total
57
+ }, 0)
58
+
59
+ return {
60
+ product,
61
+ sku: product.sku,
62
+ name: product.name,
63
+ packingType: defaultProductDetail.packingType,
64
+ packingSize: defaultProductDetail.packingSize,
65
+ uom: defaultProductDetail.uom,
66
+ qty: inventoryQty - inventoryLockedQty
67
+ }
68
+ })
69
+ )
70
+
71
+ await getConnection().transaction(async tx => {
72
+ let bundleProductInventories: any[] = await getProductBundleInventory(
73
+ warehouseDomain,
74
+ companyDomain,
75
+ inventoryProducts,
76
+ tx
77
+ )
78
+
79
+ bundleProductInventories.map(bundleProductInventory => {
80
+ inventoryProducts.push(bundleProductInventory)
81
+ })
82
+ })
83
+
84
+ for (let i = 0; i < marketplaceStores.length; i++) {
85
+ try {
86
+ const marketplaceStore: MarketplaceStore = marketplaceStores[i]
87
+
88
+ const marketplaceSetting: MarketplaceSetting = await getRepository(MarketplaceSetting).findOne({
89
+ where: { marketplaceStore, category: 'stock_allocation' }
90
+ })
91
+
92
+ for (let j = 0; j < inventoryProducts.length; j++) {
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)
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)
164
+ }
165
+ }
166
+ })
167
+ } catch (error) {
168
+ logger.error(
169
+ `interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`
170
+ )
171
+ }
172
+ }
173
+ } catch (e) {
174
+ logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`)
175
+ }
176
+ }
177
+
178
+ return true
179
+ }
180
+ }
@@ -7,6 +7,7 @@ import { syncProductsFromAccountResolver } from './sync-products-from-account'
7
7
  import { syncProductsToAccountResolver } from './sync-products-to-account'
8
8
  import { syncProductsToSellercraftResolver } from './sync-products-to-sellercraft'
9
9
  import { createDatShipments } from './create-dat-shipments'
10
+ import { autoUpdateAllMarketplaceProductVariationQuantityResolver } from './auto-update-all-marketplace-product-variation-quantity'
10
11
 
11
12
  export const Query = {
12
13
  ...fetchSyncProductsResolver,
@@ -20,5 +21,6 @@ export const Mutation = {
20
21
  ...syncProductsToAccountResolver,
21
22
  ...syncAllProductsToSellercraftResolver,
22
23
  ...sellercraftPackMarketplaceOrderResolver,
23
- ...createDatShipments
24
+ ...createDatShipments,
25
+ ...autoUpdateAllMarketplaceProductVariationQuantityResolver
24
26
  }
@@ -18,6 +18,7 @@ export const Mutation = /* GraphQL */ `
18
18
  syncAllProductsToSellercraft: Boolean @transaction
19
19
  sellercraftPackMarketplaceOrder: Boolean @transaction
20
20
  createDatShipments: Boolean @transaction
21
+ autoUpdateAllMarketplaceProductVariationQuantity(companyDomainId: String, warehouseId: String): Boolean @transaction
21
22
  `
22
23
 
23
24
  export const Types = [