@things-factory/operato-mms 6.2.102 → 6.2.104

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 (78) hide show
  1. package/dist-server/controllers/index.js +1 -0
  2. package/dist-server/controllers/index.js.map +1 -0
  3. package/dist-server/entities/index.js +5 -0
  4. package/dist-server/entities/index.js.map +1 -0
  5. package/dist-server/graphql/index.js +11 -0
  6. package/dist-server/graphql/index.js.map +1 -0
  7. package/dist-server/graphql/resolvers/index.js +10 -0
  8. package/dist-server/graphql/resolvers/index.js.map +1 -0
  9. package/dist-server/graphql/resolvers/interface-with-hub/add-release-order.js +178 -0
  10. package/dist-server/graphql/resolvers/interface-with-hub/add-release-order.js.map +1 -0
  11. package/dist-server/graphql/resolvers/interface-with-hub/auto-add-release-order.js +181 -0
  12. package/dist-server/graphql/resolvers/interface-with-hub/auto-add-release-order.js.map +1 -0
  13. package/dist-server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.js +149 -0
  14. package/dist-server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.js.map +1 -0
  15. package/dist-server/graphql/resolvers/interface-with-hub/generate-replenishment-order.js +26 -0
  16. package/dist-server/graphql/resolvers/interface-with-hub/generate-replenishment-order.js.map +1 -0
  17. package/dist-server/graphql/resolvers/interface-with-hub/index.js +12 -0
  18. package/dist-server/graphql/resolvers/interface-with-hub/index.js.map +1 -0
  19. package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js +221 -0
  20. package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js.map +1 -0
  21. package/dist-server/graphql/resolvers/shipping-provider/index.js +6 -0
  22. package/dist-server/graphql/resolvers/shipping-provider/index.js.map +1 -0
  23. package/dist-server/graphql/resolvers/shipping-provider/shipping-providers.js +32 -0
  24. package/dist-server/graphql/resolvers/shipping-provider/shipping-providers.js.map +1 -0
  25. package/dist-server/graphql/resolvers/warehouse-product/auto-link-warehouse-marketplace-product-variations.js +67 -0
  26. package/dist-server/graphql/resolvers/warehouse-product/auto-link-warehouse-marketplace-product-variations.js.map +1 -0
  27. package/dist-server/graphql/resolvers/warehouse-product/index.js +6 -0
  28. package/dist-server/graphql/resolvers/warehouse-product/index.js.map +1 -0
  29. package/dist-server/graphql/types/index.js +11 -0
  30. package/dist-server/graphql/types/index.js.map +1 -0
  31. package/dist-server/graphql/types/interface-with-hub/index.js +29 -0
  32. package/dist-server/graphql/types/interface-with-hub/index.js.map +1 -0
  33. package/dist-server/graphql/types/interface-with-hub/new-stock-replenishment.js +32 -0
  34. package/dist-server/graphql/types/interface-with-hub/new-stock-replenishment.js.map +1 -0
  35. package/dist-server/graphql/types/interface-with-hub/replenishment-order-product.js +48 -0
  36. package/dist-server/graphql/types/interface-with-hub/replenishment-order-product.js.map +1 -0
  37. package/dist-server/graphql/types/interface-with-hub/stock-replenishment-list.js +14 -0
  38. package/dist-server/graphql/types/interface-with-hub/stock-replenishment-list.js.map +1 -0
  39. package/dist-server/graphql/types/interface-with-hub/stock-replenishment.js +45 -0
  40. package/dist-server/graphql/types/interface-with-hub/stock-replenishment.js.map +1 -0
  41. package/dist-server/graphql/types/interface-with-hub/warehouse-inventory.js +15 -0
  42. package/dist-server/graphql/types/interface-with-hub/warehouse-inventory.js.map +1 -0
  43. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product-list.js +12 -0
  44. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product-list.js.map +1 -0
  45. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product.js +18 -0
  46. package/dist-server/graphql/types/interface-with-hub/warehouse-marketplace-product.js.map +1 -0
  47. package/dist-server/graphql/types/shipping-provider/index.js +10 -0
  48. package/dist-server/graphql/types/shipping-provider/index.js.map +1 -0
  49. package/dist-server/graphql/types/shipping-provider/shipping-provider-list.js +11 -0
  50. package/dist-server/graphql/types/shipping-provider/shipping-provider-list.js.map +1 -0
  51. package/dist-server/graphql/types/shipping-provider/shipping-provider.js +11 -0
  52. package/dist-server/graphql/types/shipping-provider/shipping-provider.js.map +1 -0
  53. package/dist-server/graphql/types/warehouse-product/index.js +11 -0
  54. package/dist-server/graphql/types/warehouse-product/index.js.map +1 -0
  55. package/dist-server/graphql/types/warehouse-product/warehouse-product.js +13 -0
  56. package/dist-server/graphql/types/warehouse-product/warehouse-product.js.map +1 -0
  57. package/dist-server/index.js +8 -0
  58. package/dist-server/index.js.map +1 -0
  59. package/dist-server/middlewares/index.js +4 -0
  60. package/dist-server/middlewares/index.js.map +1 -0
  61. package/dist-server/migrations/1599732967233-SeedCommonCode.js +51 -0
  62. package/dist-server/migrations/1599732967233-SeedCommonCode.js.map +1 -0
  63. package/dist-server/migrations/1608009991075-SeedUser.js +50 -0
  64. package/dist-server/migrations/1608009991075-SeedUser.js.map +1 -0
  65. package/dist-server/migrations/index.js +12 -0
  66. package/dist-server/migrations/index.js.map +1 -0
  67. package/dist-server/routers/etrax-router.js +156 -0
  68. package/dist-server/routers/etrax-router.js.map +1 -0
  69. package/dist-server/routers/shopify-pos-public-router.js +107 -0
  70. package/dist-server/routers/shopify-pos-public-router.js.map +1 -0
  71. package/dist-server/routes.js +10 -0
  72. package/dist-server/routes.js.map +1 -0
  73. package/dist-server/tsconfig.tsbuildinfo +1 -0
  74. package/dist-server/util/interface-helper.js +51 -0
  75. package/dist-server/util/interface-helper.js.map +1 -0
  76. package/dist-server/util/no-generator.js +14 -0
  77. package/dist-server/util/no-generator.js.map +1 -0
  78. package/package.json +31 -31
@@ -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, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: companyDomainId });
15
+ const marketplaceStores = await (0, shell_1.getRepository)(integration_marketplace_1.MarketplaceStore).find({
16
+ where: { domain: { id: companyDomain.id }, 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, shell_1.getRepository)(shell_1.Domain).findOne({ where: { subdomain: centerId } });
22
+ let products = await (0, shell_1.getRepository)(product_base_1.Product).find({
23
+ where: { domain: { id: companyDomain.id } },
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, shell_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, shell_1.getRepository)(integration_marketplace_1.MarketplaceSetting).findOne({
70
+ where: { marketplaceStore: { id: marketplaceStore.id }, 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: { id: companyDomain.id }, 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/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAEvC,6CAA4C;AAC5C,qFAAwE;AACxE,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAqE;AACrE,iDAA6D;AAC7D,mEAAsH;AAEzG,QAAA,wDAAwD,GAAG;IACtE,KAAK,CAAC,gDAAgD,CACpD,CAAM,EACN,EAAE,eAAe,EAAE,WAAW,EAAE,EAChC,OAAwB;QAExB,MAAM,aAAa,GAAW,MAAM,IAAA,qBAAa,EAAC,cAAM,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;QAE5F,MAAM,iBAAiB,GAAuB,MAAM,IAAA,qBAAa,EAAC,0CAAgB,CAAC,CAAC,IAAI,CAAC;YACvF,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,aAAa,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;YAC7D,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;QAClD,MAAM,eAAe,GAAW,MAAM,IAAA,qBAAa,EAAC,cAAM,CAAC,CAAC,OAAO,CAAC,EAAE,KA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AY,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","sourcesContent":["import { getConnection } from 'typeorm'\n\nimport { logger } from '@things-factory/env'\nimport { FulfillmentAPI } from '@things-factory/integration-fulfillment'\nimport { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'\nimport { MarketplaceProductVariation } from '@things-factory/marketplace-base'\nimport { Product, ProductDetail } from '@things-factory/product-base'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { getProductBundleInventory, Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'\n\nexport const autoUpdateAllMarketplaceProductVariationQuantityResolver = {\n async autoUpdateAllMarketplaceProductVariationQuantity(\n _: any,\n { companyDomainId, warehouseId },\n context: ResolverContext\n ) {\n const companyDomain: Domain = await getRepository(Domain).findOneBy({ id: companyDomainId })\n\n const marketplaceStores: MarketplaceStore[] = await getRepository(MarketplaceStore).find({\n where: { domain: { id: companyDomain.id }, status: 'ACTIVE' },\n relations: ['marketplaceDistributors']\n })\n\n const fulfilmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)\n const centerId: string = fulfilmentCenter.centerId\n const warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })\n\n let products: Product[] = await getRepository(Product).find({\n where: { domain: { id: companyDomain.id } },\n relations: ['productDetails']\n })\n\n let inventoryProducts: any[] = await Promise.all(\n products.map(async product => {\n const productDetails: ProductDetail[] = product.productDetails\n const defaultProductDetail: ProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0]\n\n let qb = await getRepository(Inventory).createQueryBuilder('inv')\n qb.leftJoinAndSelect('inv.location', 'loc')\n .andWhere('\"inv\".\"domain_id\" = :domainId')\n .andWhere('\"inv\".\"product_id\" = :productId')\n .andWhere('\"inv\".\"status\" != :status')\n .andWhere('\"loc\".\"type\" NOT IN (:...locationTypes)')\n .setParameters({\n domainId: warehouseDomain.id,\n productId: product.id,\n status: INVENTORY_STATUS.TERMINATED,\n locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]\n })\n\n let inventories: Inventory[] = await qb.getMany()\n\n const inventoryQty: number = inventories.reduce((total, currentValue) => {\n total += currentValue.qty\n return total\n }, 0)\n\n const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {\n total += currentValue.lockedQty\n return total\n }, 0)\n\n return {\n product,\n sku: product.sku,\n name: product.name,\n packingType: defaultProductDetail.packingType,\n packingSize: defaultProductDetail.packingSize,\n uom: defaultProductDetail.uom,\n qty: inventoryQty - inventoryLockedQty\n }\n })\n )\n\n await getConnection().transaction(async tx => {\n let bundleProductInventories: any[] = await getProductBundleInventory(\n warehouseDomain,\n companyDomain,\n inventoryProducts,\n tx\n )\n\n bundleProductInventories.map(bundleProductInventory => {\n inventoryProducts.push(bundleProductInventory)\n })\n })\n\n for (let i = 0; i < marketplaceStores.length; i++) {\n try {\n const marketplaceStore: MarketplaceStore = marketplaceStores[i]\n\n const marketplaceSetting: MarketplaceSetting = await getRepository(MarketplaceSetting).findOne({\n where: { marketplaceStore: { id: marketplaceStore.id }, category: 'stock_allocation' }\n })\n\n for (let j = 0; j < inventoryProducts.length; j++) {\n try {\n await getConnection().transaction(async tx => {\n const inventoryProduct = inventoryProducts[j]\n const marketplaceProductVariations: MarketplaceProductVariation[] = await tx\n .getRepository(MarketplaceProductVariation)\n .find({\n where: { domain: { id: companyDomain.id }, sku: inventoryProduct.sku },\n relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']\n })\n\n let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(\n productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id\n )\n\n let percentageValue: number = 100\n if (storeProductVariations) {\n for (let k = 0; k < storeProductVariations.length; k++) {\n let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]\n if (marketplaceSetting) {\n percentageValue = parseInt(marketplaceSetting.value)\n }\n\n let remainQty: number = Math.floor(\n (inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)\n )\n if (remainQty < 0) remainQty = 0\n\n let productVariationLocationId = storeProductVariation?.locationId\n let adjustQty: number = remainQty\n\n if (marketplaceStore.platform === 'shopify') {\n let locationIds: any[] = JSON.parse(productVariationLocationId)\n adjustQty = adjustQty - storeProductVariation.qty\n if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id\n }\n\n let validMarketplaceDistributors: any[] = []\n if (marketplaceStore.marketplaceDistributors) {\n validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(\n distributor => distributor.status === 'ACTIVE'\n )\n }\n\n const hasVariation: boolean = storeProductVariation?.marketplaceProduct?.hasVariation\n\n if (hasVariation) {\n await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [\n {\n itemId: storeProductVariation.marketplaceProduct.itemId,\n variationId: storeProductVariation.variationId,\n variationSku: storeProductVariation.variationSku,\n qty: adjustQty,\n locationId: productVariationLocationId,\n inventoryItemId: storeProductVariation.inventoryItemId,\n distributors: validMarketplaceDistributors\n }\n ])\n } else {\n await StoreAPI.updateStoreProductStock(marketplaceStore, [\n {\n itemId: storeProductVariation.marketplaceProduct.itemId,\n variationId: storeProductVariation.variationId,\n variationSku: storeProductVariation.variationSku,\n qty: adjustQty,\n distributors: validMarketplaceDistributors\n }\n ])\n }\n\n storeProductVariation.qty = remainQty\n await tx.getRepository(MarketplaceProductVariation).save(storeProductVariation)\n }\n }\n })\n } catch (error) {\n logger.error(\n `interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]inventoryProducts: ${error}`\n )\n }\n }\n } catch (e) {\n logger.error(`interface-with-hub[autoUpdateAllMarketplaceProductVariationQuantity]marketplaceStores: ${e}`)\n }\n }\n\n return true\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateReplenishmentOrderResolver = void 0;
4
+ const biz_base_1 = require("@things-factory/biz-base");
5
+ const integration_fulfillment_1 = require("@things-factory/integration-fulfillment");
6
+ const marketplace_base_1 = require("@things-factory/marketplace-base");
7
+ exports.generateReplenishmentOrderResolver = {
8
+ async generateReplenishmentOrder(_, { storeReplenishmentId, warehouseId }, context) {
9
+ const { tx } = context.state;
10
+ let storeReplenishment = await tx.getRepository(marketplace_base_1.StoreReplenishment).findOne({
11
+ where: { id: storeReplenishmentId },
12
+ relations: ['storeReplenishmentItems']
13
+ });
14
+ var fulfillmentCenter = await integration_fulfillment_1.FulfillmentAPI.getFulfillmentCenter(warehouseId);
15
+ var centerId = fulfillmentCenter.centerId;
16
+ var subdominBizplace = await (0, biz_base_1.getSubdomainBizplace)(centerId);
17
+ var warehouseBizplaceId = subdominBizplace === null || subdominBizplace === void 0 ? void 0 : subdominBizplace.id;
18
+ var arrivalNotice = await integration_fulfillment_1.FulfillmentAPI.createInboundOrder(fulfillmentCenter, {
19
+ warehouseBizplaceId,
20
+ storeReplenishment
21
+ });
22
+ storeReplenishment.arrivalNoticeId = arrivalNotice.id;
23
+ await tx.getRepository(marketplace_base_1.StoreReplenishment).save(storeReplenishment);
24
+ }
25
+ };
26
+ //# sourceMappingURL=generate-replenishment-order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-replenishment-order.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/generate-replenishment-order.ts"],"names":[],"mappings":";;;AAAA,uDAAyE;AACzE,qFAAwE;AACxE,uEAAqE;AAExD,QAAA,kCAAkC,GAAG;IAChD,KAAK,CAAC,0BAA0B,CAC9B,CAAO,EACP,EAAE,oBAAoB,EAAE,WAAW,EAAyD,EAC5F,OAAwB;QAExB,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE5B,IAAI,kBAAkB,GAAuB,MAAM,EAAE,CAAC,aAAa,CAAC,qCAAkB,CAAC,CAAC,OAAO,CAAC;YAC9F,KAAK,EAAE,EAAE,EAAE,EAAE,oBAAoB,EAAE;YACnC,SAAS,EAAE,CAAC,yBAAyB,CAAC;SACvC,CAAC,CAAA;QAEF,IAAI,iBAAiB,GAAG,MAAM,wCAAc,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAA;QAC9E,IAAI,QAAQ,GAAW,iBAAiB,CAAC,QAAQ,CAAA;QAEjD,IAAI,gBAAgB,GAAa,MAAM,IAAA,+BAAoB,EAAC,QAAQ,CAAC,CAAA;QACrE,IAAI,mBAAmB,GAAW,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,EAAE,CAAA;QAEtD,IAAI,aAAa,GAAG,MAAM,wCAAc,CAAC,kBAAkB,CAAC,iBAAiB,EAAE;YAC7E,mBAAmB;YACnB,kBAAkB;SACnB,CAAC,CAAA;QAEF,kBAAkB,CAAC,eAAe,GAAG,aAAa,CAAC,EAAE,CAAA;QACrD,MAAM,EAAE,CAAC,aAAa,CAAC,qCAAkB,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IACrE,CAAC;CACF,CAAA","sourcesContent":["import { Bizplace, getSubdomainBizplace } from '@things-factory/biz-base'\nimport { FulfillmentAPI } from '@things-factory/integration-fulfillment'\nimport { StoreReplenishment } from '@things-factory/marketplace-base'\n\nexport const generateReplenishmentOrderResolver = {\n async generateReplenishmentOrder(\n _: void,\n { storeReplenishmentId, warehouseId }: { storeReplenishmentId: string; warehouseId: string },\n context: ResolverContext\n ): Promise<any> {\n const { tx } = context.state\n\n let storeReplenishment: StoreReplenishment = await tx.getRepository(StoreReplenishment).findOne({\n where: { id: storeReplenishmentId },\n relations: ['storeReplenishmentItems']\n })\n\n var fulfillmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)\n var centerId: string = fulfillmentCenter.centerId\n\n var subdominBizplace: Bizplace = await getSubdomainBizplace(centerId)\n var warehouseBizplaceId: string = subdominBizplace?.id\n\n var arrivalNotice = await FulfillmentAPI.createInboundOrder(fulfillmentCenter, {\n warehouseBizplaceId,\n storeReplenishment\n })\n\n storeReplenishment.arrivalNoticeId = arrivalNotice.id\n await tx.getRepository(StoreReplenishment).save(storeReplenishment)\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.warehouseMarketplaceProduct = exports.Mutation = exports.Query = void 0;
4
+ const add_release_order_1 = require("./add-release-order");
5
+ const auto_add_release_order_1 = require("./auto-add-release-order");
6
+ const auto_update_all_marketplace_product_variation_quantity_1 = require("./auto-update-all-marketplace-product-variation-quantity");
7
+ const generate_replenishment_order_1 = require("./generate-replenishment-order");
8
+ const warehouse_marketplace_products_1 = require("./warehouse-marketplace-products");
9
+ Object.defineProperty(exports, "warehouseMarketplaceProduct", { enumerable: true, get: function () { return warehouse_marketplace_products_1.warehouseMarketplaceProduct; } });
10
+ exports.Query = Object.assign({}, warehouse_marketplace_products_1.warehouseMarketplaceProductsResolver);
11
+ exports.Mutation = Object.assign(Object.assign(Object.assign(Object.assign({}, add_release_order_1.addReleaseOrderResolver), auto_add_release_order_1.autoAddReleaseOrderResolver), generate_replenishment_order_1.generateReplenishmentOrderResolver), auto_update_all_marketplace_product_variation_quantity_1.autoUpdateAllMarketplaceProductVariationQuantityResolver);
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/index.ts"],"names":[],"mappings":";;;AAAA,2DAA6D;AAC7D,qEAAsE;AACtE,qIAAmI;AACnI,iFAAmF;AACnF,qFAAoH;AAa3G,4GAbA,4DAA2B,OAaA;AAXvB,QAAA,KAAK,qBACb,qEAAoC,EACxC;AAEY,QAAA,QAAQ,+DAChB,2CAAuB,GACvB,oDAA2B,GAC3B,iEAAkC,GAClC,iHAAwD,EAC5D","sourcesContent":["import { addReleaseOrderResolver } from './add-release-order'\nimport { autoAddReleaseOrderResolver } from './auto-add-release-order'\nimport { autoUpdateAllMarketplaceProductVariationQuantityResolver } from './auto-update-all-marketplace-product-variation-quantity'\nimport { generateReplenishmentOrderResolver } from './generate-replenishment-order'\nimport { warehouseMarketplaceProduct, warehouseMarketplaceProductsResolver } from './warehouse-marketplace-products'\n\nexport const Query = {\n ...warehouseMarketplaceProductsResolver\n}\n\nexport const Mutation = {\n ...addReleaseOrderResolver,\n ...autoAddReleaseOrderResolver,\n ...generateReplenishmentOrderResolver,\n ...autoUpdateAllMarketplaceProductVariationQuantityResolver\n}\n\nexport { warehouseMarketplaceProduct }\n"]}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.warehouseMarketplaceProduct = exports.warehouseMarketplaceProductsResolver = void 0;
4
+ const biz_base_1 = require("@things-factory/biz-base");
5
+ exports.warehouseMarketplaceProductsResolver = {
6
+ async warehouseMarketplaceProducts(_, params, context) {
7
+ try {
8
+ const { domain, user, tx } = context.state;
9
+ return warehouseMarketplaceProduct(params, domain, user, tx);
10
+ }
11
+ catch (error) {
12
+ throw error;
13
+ }
14
+ }
15
+ };
16
+ async function warehouseMarketplaceProduct(params, domain, user, tx) {
17
+ const productFilters = params.filters.filter(x => x.name == 'product_info');
18
+ const filters = params.filters.filter(x => x.name != 'product_info');
19
+ const companyBizplace = await (0, biz_base_1.getCompanyBizplace)(domain, user);
20
+ const myBizplace = await (0, biz_base_1.getMyBizplace)(domain, user);
21
+ params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [companyBizplace.id, myBizplace.id] }];
22
+ const bizplaceIds = params.filters
23
+ .find((filter) => filter.name === 'bizplace_id')
24
+ .value.map((id) => `'${id}'`)
25
+ .join();
26
+ let productQuery = '';
27
+ if (productFilters && productFilters.length > 0) {
28
+ let productInfo = productFilters[0];
29
+ productQuery = ` AND (
30
+ Lower("Product"."sku") LIKE '${productInfo.value.toLowerCase()}'
31
+ OR Lower("Product"."name") LIKE '${productInfo.value.toLowerCase()}'
32
+ OR Lower("Product"."description") LIKE '${productInfo.value.toLowerCase()}')`;
33
+ }
34
+ await tx.query(`
35
+ CREATE TEMP TABLE "temp_products" ON COMMIT DROP AS (
36
+ SELECT * FROM (
37
+ SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
38
+ "Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
39
+ "Product"."bizplace_id" AS "product_bizplace_id", 'PRODUCT' AS "type"
40
+ FROM products "Product"
41
+ WHERE 1=1
42
+ AND "Product"."deleted_at" IS NULL
43
+ AND "Product"."bizplace_id" IN (${bizplaceIds})
44
+ ${productQuery}
45
+ ) d1
46
+ UNION ALL
47
+ SELECT * FROM
48
+ (
49
+ SELECT "Product"."id" AS "product_id", "Product"."sku" AS "product_sku", "Product"."name" AS "product_name",
50
+ "Product"."description" AS "product_description", "Product"."creator_id", "Product"."updater_id",
51
+ "Product"."bizplace_id" AS "product_bizplace_id", 'BUNDLE' AS "type"
52
+ FROM product_bundles "Product"
53
+ WHERE 1 = 1
54
+ AND "Product"."status" = 'ACTIVATED'
55
+ AND "Product"."bizplace_id" IN (${bizplaceIds})
56
+ ${productQuery}
57
+ ) d2
58
+ )
59
+ `);
60
+ await tx.query(`
61
+ CREATE TEMP TABLE "temp_order_inventories" ON COMMIT DROP AS (
62
+ SELECT
63
+ SUM(oi.release_qty) AS release_qty, SUM(oi.release_uom_value) AS release_uom_value, oi.batch_id, oi.batch_id_ref,
64
+ oi.product_id, p.product_name, oi.packing_type, oi.packing_size, oi.uom
65
+ FROM
66
+ order_inventories oi
67
+ LEFT JOIN
68
+ temp_products p ON oi.product_id = p.product_id
69
+ INNER JOIN
70
+ domains d2 on d2.id = oi.domain_id and d2.ext_type ='warehouse'
71
+ INNER JOIN
72
+ fulfillment_centers fc ON fc.center_id = d2.subdomain
73
+ WHERE
74
+ fc.domain_id = $1
75
+ AND (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')
76
+ AND oi.batch_id NOTNULL AND oi.product_id NOTNULL AND oi.packing_type NOTNULL AND oi.packing_size NOTNULL AND oi.inventory_id IS NULL
77
+ GROUP BY
78
+ oi.batch_id, oi.batch_id_ref, oi.product_id, oi.packing_type,
79
+ oi.packing_size, oi.uom, p.product_name
80
+ );
81
+ `, [domain.id]);
82
+ await tx.query(`
83
+ CREATE TEMP TABLE "temp_inventory" ON COMMIT DROP AS (
84
+ select "i2".*, coalesce("oi".release_qty,0) + coalesce("i2".locked_qty,0) as "inventory_locked_qty" from (
85
+ select "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
86
+ "i2"."product_id", sum(coalesce("locked_qty",0)) as "locked_qty", sum(coalesce("qty",0)) as "inventory_qty",
87
+ "i2"."domain_id", "i2"."packing_type", "i2"."packing_size", "i2"."uom"
88
+ from inventories "i2"
89
+ inner join warehouses "w" on "w"."id" = "i2"."warehouse_id"
90
+ inner join domains "d2" on "d2"."id" = "w"."domain_id" and "d2"."ext_type" ='warehouse'
91
+ inner join fulfillment_centers "fc" ON "fc"."center_id" = "d2"."subdomain"
92
+ inner join (
93
+ select "Product"."product_id" from (
94
+ select case when "Product"."type" = 'PRODUCT' then "Product"."product_id" else "pbs"."product_id" end as "product_id"
95
+ from temp_products "Product"
96
+ left join product_bundles "pb" on "pb"."id" = "Product"."product_id"
97
+ left join product_bundle_settings "pbs" on "pbs"."product_bundle_id" = "pb"."id"
98
+ ) "Product"
99
+ group by "Product"."product_id"
100
+ ) "Product" on "Product"."product_id" = "i2"."product_id"
101
+ where "fc"."domain_id" = $1
102
+ and "i2"."status" = 'STORED'
103
+ group by "i2"."domain_id", "fc"."id", "fc"."name", "i2"."product_id", "i2"."packing_type", "i2"."packing_size", "i2"."uom"
104
+ ) as "i2"
105
+ left join temp_order_inventories "oi" on "i2"."product_id" = "oi"."product_id"
106
+ AND "i2"."packing_type" = "oi"."packing_type"
107
+ AND "i2"."packing_size" = "oi"."packing_size"
108
+ AND "i2"."uom" = "oi"."uom"
109
+ )
110
+ `, [domain.id]);
111
+ await tx.query(`
112
+ CREATE TEMP TABLE "temp_json_warehouse_marketplace_products" ON COMMIT DROP AS (
113
+ select "product_id", array_to_json(array_agg(row_to_json(dt))) AS "Json_marketplaceProducts" FROM (
114
+ select "dt"."marketplace_store_id", "dt"."product_id", "dt"."sku", array_agg(row_to_json(dt)) as product_variation
115
+ from (
116
+ select "mp"."marketplace_store_id" as "marketplace_store_id", "mpv"."sku", "mpv"."id" as "marketplace_product_variation_id",
117
+ concat("mpv"."variation_sku", ' (', "mpv"."name", ')') as "name", "mpv"."qty" as "qty", "mpv"."reserve_qty" as "reserve_qty",
118
+ "Product"."product_id" AS "product_id"
119
+ from marketplace_product_variations "mpv"
120
+ inner join marketplace_products "mp" on "mp"."id" = "mpv"."marketplace_product_id"
121
+ inner join temp_products "Product" on "mpv"."sku" = "Product"."product_sku"
122
+ ) as "dt"
123
+ group by "dt"."marketplace_store_id", "dt"."sku", "dt"."product_id"
124
+ ) "dt" group by "dt"."product_id"
125
+ )
126
+ `);
127
+ await tx.query(`
128
+ CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (
129
+ select "product_id", array_to_json(array_agg((row_to_json("dt")))) AS "Json_warehouseInventory" from(
130
+ select "domain_id", "fulfillment_id", "fulfillment_name",
131
+ "product_id", "inventory_locked_qty", "inventory_qty"
132
+ from temp_inventory
133
+ union
134
+ select "bundledInv"."domain_id", "bundledInv"."fulfillment_id", "bundledInv"."fulfillment_name", "bundledInv"."product_id",
135
+ max("bundledInv"."inventory_locked_qty") as "inventory_locked_qty", min("bundledInv"."inventory_qty") as "inventory_qty" from (
136
+ select "Product"."product_id", fc.domain_id, "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
137
+ "pbs"."bundle_qty",
138
+ case when "pbs"."bundle_qty" <= 0 then 0 else floor(greatest("i2"."inventory_qty", 0)/ "pbs"."bundle_qty")- floor((greatest("i2"."inventory_qty", 0) - greatest("i2"."inventory_locked_qty",0)) / "pbs"."bundle_qty") end AS "inventory_locked_qty",
139
+ case when "pbs"."bundle_qty" <= 0 then 0 else floor(greatest("i2"."inventory_qty", 0)/ "pbs"."bundle_qty") end AS "inventory_qty"
140
+ from temp_products "Product"
141
+ inner join product_bundle_settings pbs ON pbs.product_bundle_id = "Product"."product_id"
142
+ inner join products p on p.id = pbs.product_id
143
+ cross join fulfillment_centers fc
144
+ inner join domains "d2" on "d2"."ext_type" ='warehouse' and "fc"."center_id" = "d2"."subdomain"
145
+ left join temp_inventory i2 ON i2.product_id = pbs.product_id and "d2"."id" = "i2"."domain_id"
146
+ where "fc"."domain_id" = $1
147
+ order by fc.id, "Product"."product_sku", p.sku
148
+ ) "bundledInv"
149
+ group by "domain_id","fulfillment_id","fulfillment_name","product_id"
150
+ ) "dt" group by "dt"."product_id"
151
+ )
152
+ `, [domain.id]);
153
+ await tx.query(`
154
+ CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (
155
+ SELECT "Product"."product_id" AS "Product_id", "Product"."product_sku" AS "Product_sku",
156
+ "Product"."product_name" AS "Product_name", "Product"."product_description" AS "Product_description",
157
+ "Product"."product_bizplace_id" AS "Product_bizplace_id",
158
+ "Product"."creator_id" AS "Product_creator_id", "Product"."updater_id" AS "Product_updater_id",
159
+ "Bizplace"."name" AS "Bizplace_name", "Bizplace"."description" AS "Bizplace_description", "Bizplace"."address" AS "Bizplace_address", "Bizplace"."postal_code" AS "Bizplace_postal_code",
160
+ "Bizplace"."latlng" AS "Bizplace_latlng", "Bizplace"."status" AS "Bizplace_status", "Bizplace"."created_at" AS "Bizplace_created_at", "Bizplace"."updated_at" AS "Bizplace_updated_at",
161
+ "Bizplace"."domain_id" AS "Bizplace_domain_id", "Bizplace"."company_id" AS "Bizplace_company_id", "Bizplace"."creator_id" AS "Bizplace_creator_id", "Bizplace"."updater_id" AS "Bizplace_updater_id",
162
+ "Creator"."id" AS "Creator_id", "Creator"."name" AS "Creator_name", "Creator"."description" AS "Creator_description", "Creator"."email" AS "Creator_email",
163
+ "Updater"."id" AS "Updater_id", "Updater"."name" AS "Updater_name", "Updater"."description" AS "Updater_description", "Updater"."email" AS "Updater_email"
164
+ ,COALESCE("whInv"."Json_warehouseInventory", null) AS "Json_warehouseInventory"
165
+ ,COALESCE("mktPrd"."Json_marketplaceProducts", null) AS "Json_marketplaceProducts"
166
+ FROM "temp_products" "Product"
167
+ LEFT JOIN "bizplaces" "Bizplace" ON "Bizplace"."id" = "Product"."product_bizplace_id"
168
+ LEFT JOIN "users" "Creator" ON "Creator"."id"="Product"."creator_id"
169
+ LEFT JOIN "users" "Updater" ON "Updater"."id"="Product"."updater_id"
170
+ LEFT JOIN "temp_json_warehouse_inventory" "whInv" ON "whInv"."product_id" = "Product"."product_id"
171
+ LEFT JOIN "temp_json_warehouse_marketplace_products" "mktPrd" ON "mktPrd"."product_id" = "Product"."product_id"
172
+ )
173
+ `);
174
+ const offsetQuery = (params === null || params === void 0 ? void 0 : params.pagination)
175
+ ? `OFFSET ${(params.pagination.page - 1) * params.pagination.limit} LIMIT ${params.pagination.limit}`
176
+ : '';
177
+ const total = await tx.query(`select count(*) from temp_warehouse_marketplace_products`);
178
+ const items = await tx.query(`
179
+ select * from temp_warehouse_marketplace_products ${offsetQuery}
180
+ `);
181
+ return {
182
+ items: items.map((itm, index) => {
183
+ return {
184
+ seq: index + ((params === null || params === void 0 ? void 0 : params.pagination) ? (params.pagination.page - 1) * params.pagination.limit + 1 : 0),
185
+ id: itm.Product_id,
186
+ sku: itm.Product_sku,
187
+ name: itm.Product_name,
188
+ description: itm.Product_description,
189
+ marketplaceProduct: itm.Json_marketplaceProducts
190
+ ? itm.Json_marketplaceProducts.map(product => {
191
+ return {
192
+ marketplaceStore: { id: product.marketplace_store_id },
193
+ marketplaceProductVariations: product.product_variation.map(variation => {
194
+ return {
195
+ id: variation.marketplace_product_variation_id,
196
+ name: variation.name,
197
+ qty: variation.qty,
198
+ reserveQty: variation.reserve_qty
199
+ };
200
+ })
201
+ };
202
+ })
203
+ : null,
204
+ warehouseInventory: itm.Json_warehouseInventory
205
+ ? itm.Json_warehouseInventory.map(inventory => {
206
+ return {
207
+ bizplace: { id: inventory.fulfillment_id, name: inventory.fulfillment_name },
208
+ product: { id: inventory.product_id },
209
+ qty: inventory.inventory_qty,
210
+ lockedQty: inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0,
211
+ remainQty: inventory.inventory_qty - (inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0)
212
+ };
213
+ })
214
+ : null
215
+ };
216
+ }),
217
+ total: total[0].count
218
+ };
219
+ }
220
+ exports.warehouseMarketplaceProduct = warehouseMarketplaceProduct;
221
+ //# sourceMappingURL=warehouse-marketplace-products.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warehouse-marketplace-products.js","sourceRoot":"","sources":["../../../../server/graphql/res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AC;oBACJ,CAAC,CAAC,IAAI;gBACR,kBAAkB,EAAE,GAAG,CAAC,uBAAuB;oBAC7C,CAAC,CAAC,GAAG,CAAC,uBAAuB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;wBAC1C,OAAO;4BACL,QAAQ,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,SAAS,CAAC,gBAAgB,EAAE;4BAC5E,OAAO,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,UAAU,EAAE;4BACrC,GAAG,EAAE,SAAS,CAAC,aAAa;4BAC5B,SAAS,EAAE,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;4BAC9E,SAAS,EACP,SAAS,CAAC,aAAa,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;yBAClG,CAAA;oBACH,CAAC,CAAC;oBACJ,CAAC,CAAC,IAAI;aACT,CAAA;QACH,CAAC,CAAC;QACF,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;KACtB,CAAA;AACH,CAAC;AArOD,kEAqOC","sourcesContent":["import { EntityManager } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Bizplace, getCompanyBizplace, getMyBizplace } from '@things-factory/biz-base'\nimport { Domain, ListParam } from '@things-factory/shell'\n\nexport const warehouseMarketplaceProductsResolver = {\n async warehouseMarketplaceProducts(_: any, params: ListParam, context: ResolverContext): Promise<any> {\n try {\n const { domain, user, tx } = context.state\n return warehouseMarketplaceProduct(params, domain, user, tx)\n } catch (error) {\n throw error\n }\n }\n}\n\nexport async function warehouseMarketplaceProduct(params: ListParam, domain: Domain, user: User, tx?: EntityManager) {\n const productFilters = params.filters.filter(x => x.name == 'product_info')\n const filters = params.filters.filter(x => x.name != 'product_info')\n\n const companyBizplace: Bizplace = await getCompanyBizplace(domain, user)\n const myBizplace: Bizplace = await getMyBizplace(domain, user)\n\n params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [companyBizplace.id, myBizplace.id] }]\n\n const bizplaceIds: string = params.filters\n .find((filter: any) => filter.name === 'bizplace_id')\n .value.map((id: string) => `'${id}'`)\n .join()\n\n let productQuery = ''\n if (productFilters && productFilters.length > 0) {\n let productInfo = productFilters[0]\n productQuery = ` AND (\n Lower(\"Product\".\"sku\") LIKE '${productInfo.value.toLowerCase()}'\n OR Lower(\"Product\".\"name\") LIKE '${productInfo.value.toLowerCase()}'\n OR Lower(\"Product\".\"description\") LIKE '${productInfo.value.toLowerCase()}')`\n }\n\n await tx.query(`\n CREATE TEMP TABLE \"temp_products\" ON COMMIT DROP AS (\n SELECT * FROM (\n SELECT \"Product\".\"id\" AS \"product_id\", \"Product\".\"sku\" AS \"product_sku\", \"Product\".\"name\" AS \"product_name\", \n \"Product\".\"description\" AS \"product_description\", \"Product\".\"creator_id\", \"Product\".\"updater_id\", \n \"Product\".\"bizplace_id\" AS \"product_bizplace_id\", 'PRODUCT' AS \"type\" \n FROM products \"Product\" \n WHERE 1=1\n AND \"Product\".\"deleted_at\" IS NULL \n AND \"Product\".\"bizplace_id\" IN (${bizplaceIds})\n ${productQuery}\n ) d1\n UNION ALL\n SELECT * FROM\n (\n SELECT \"Product\".\"id\" AS \"product_id\", \"Product\".\"sku\" AS \"product_sku\", \"Product\".\"name\" AS \"product_name\",\n \"Product\".\"description\" AS \"product_description\", \"Product\".\"creator_id\", \"Product\".\"updater_id\", \n \"Product\".\"bizplace_id\" AS \"product_bizplace_id\", 'BUNDLE' AS \"type\" \n FROM product_bundles \"Product\" \n WHERE 1 = 1\n AND \"Product\".\"status\" = 'ACTIVATED'\n AND \"Product\".\"bizplace_id\" IN (${bizplaceIds})\n ${productQuery}\n ) d2\n )\n `)\n\n await tx.query(\n `\n CREATE TEMP TABLE \"temp_order_inventories\" ON COMMIT DROP AS (\t\n SELECT\n SUM(oi.release_qty) AS release_qty, SUM(oi.release_uom_value) AS release_uom_value, oi.batch_id, oi.batch_id_ref, \n oi.product_id, p.product_name, oi.packing_type, oi.packing_size, oi.uom\n FROM\n order_inventories oi\n LEFT JOIN\n temp_products p ON oi.product_id = p.product_id\n INNER JOIN \n domains d2 on d2.id = oi.domain_id and d2.ext_type ='warehouse'\n INNER JOIN \n fulfillment_centers fc ON fc.center_id = d2.subdomain \n WHERE\n fc.domain_id = $1\n AND (oi.status = 'PENDING' or oi.status = 'PENDING_RECEIVE' or oi.status = 'PENDING_WORKSHEET' or oi.status = 'PENDING_SPLIT')\n AND oi.batch_id NOTNULL AND oi.product_id NOTNULL AND oi.packing_type NOTNULL AND oi.packing_size NOTNULL AND oi.inventory_id IS NULL \n GROUP BY\n oi.batch_id, oi.batch_id_ref, oi.product_id, oi.packing_type,\n oi.packing_size, oi.uom, p.product_name\n );\n `,\n [domain.id]\n )\n\n await tx.query(\n `\n CREATE TEMP TABLE \"temp_inventory\" ON COMMIT DROP AS (\t\n select \"i2\".*, coalesce(\"oi\".release_qty,0) + coalesce(\"i2\".locked_qty,0) as \"inventory_locked_qty\" from (\n select \"fc\".\"id\" as \"fulfillment_id\", \"fc\".\"name\" as \"fulfillment_name\",\n \"i2\".\"product_id\", sum(coalesce(\"locked_qty\",0)) as \"locked_qty\", sum(coalesce(\"qty\",0)) as \"inventory_qty\",\n \"i2\".\"domain_id\", \"i2\".\"packing_type\", \"i2\".\"packing_size\", \"i2\".\"uom\"\n from inventories \"i2\"\n inner join warehouses \"w\" on \"w\".\"id\" = \"i2\".\"warehouse_id\" \n inner join domains \"d2\" on \"d2\".\"id\" = \"w\".\"domain_id\" and \"d2\".\"ext_type\" ='warehouse'\n inner join fulfillment_centers \"fc\" ON \"fc\".\"center_id\" = \"d2\".\"subdomain\" \n inner join (\n select \"Product\".\"product_id\" from (\n select case when \"Product\".\"type\" = 'PRODUCT' then \"Product\".\"product_id\" else \"pbs\".\"product_id\" end as \"product_id\"\n from temp_products \"Product\" \n left join product_bundles \"pb\" on \"pb\".\"id\" = \"Product\".\"product_id\" \n left join product_bundle_settings \"pbs\" on \"pbs\".\"product_bundle_id\" = \"pb\".\"id\"\n ) \"Product\" \n group by \"Product\".\"product_id\"\n ) \"Product\" on \"Product\".\"product_id\" = \"i2\".\"product_id\" \n where \"fc\".\"domain_id\" = $1\n and \"i2\".\"status\" = 'STORED'\n group by \"i2\".\"domain_id\", \"fc\".\"id\", \"fc\".\"name\", \"i2\".\"product_id\", \"i2\".\"packing_type\", \"i2\".\"packing_size\", \"i2\".\"uom\"\n ) as \"i2\"\n left join temp_order_inventories \"oi\" on \"i2\".\"product_id\" = \"oi\".\"product_id\" \n AND \"i2\".\"packing_type\" = \"oi\".\"packing_type\" \n AND \"i2\".\"packing_size\" = \"oi\".\"packing_size\" \n AND \"i2\".\"uom\" = \"oi\".\"uom\"\n )\n `,\n [domain.id]\n )\n\n await tx.query(`\n CREATE TEMP TABLE \"temp_json_warehouse_marketplace_products\" ON COMMIT DROP AS (\n select \"product_id\", array_to_json(array_agg(row_to_json(dt))) AS \"Json_marketplaceProducts\" FROM (\n select \"dt\".\"marketplace_store_id\", \"dt\".\"product_id\", \"dt\".\"sku\", array_agg(row_to_json(dt)) as product_variation\n from (\n select \"mp\".\"marketplace_store_id\" as \"marketplace_store_id\", \"mpv\".\"sku\", \"mpv\".\"id\" as \"marketplace_product_variation_id\",\n concat(\"mpv\".\"variation_sku\", ' (', \"mpv\".\"name\", ')') as \"name\", \"mpv\".\"qty\" as \"qty\", \"mpv\".\"reserve_qty\" as \"reserve_qty\",\n \"Product\".\"product_id\" AS \"product_id\"\n from marketplace_product_variations \"mpv\"\n inner join marketplace_products \"mp\" on \"mp\".\"id\" = \"mpv\".\"marketplace_product_id\"\n inner join temp_products \"Product\" on \"mpv\".\"sku\" = \"Product\".\"product_sku\"\n ) as \"dt\"\n group by \"dt\".\"marketplace_store_id\", \"dt\".\"sku\", \"dt\".\"product_id\"\n ) \"dt\" group by \"dt\".\"product_id\"\n )\n `)\n\n await tx.query(\n `\n CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (\n select \"product_id\", array_to_json(array_agg((row_to_json(\"dt\")))) AS \"Json_warehouseInventory\" from(\n select \"domain_id\", \"fulfillment_id\", \"fulfillment_name\",\n \"product_id\", \"inventory_locked_qty\", \"inventory_qty\"\n from temp_inventory\n union \n select \"bundledInv\".\"domain_id\", \"bundledInv\".\"fulfillment_id\", \"bundledInv\".\"fulfillment_name\", \"bundledInv\".\"product_id\", \n max(\"bundledInv\".\"inventory_locked_qty\") as \"inventory_locked_qty\", min(\"bundledInv\".\"inventory_qty\") as \"inventory_qty\" from (\n select \"Product\".\"product_id\", fc.domain_id, \"fc\".\"id\" as \"fulfillment_id\", \"fc\".\"name\" as \"fulfillment_name\",\n \"pbs\".\"bundle_qty\",\n case when \"pbs\".\"bundle_qty\" <= 0 then 0 else floor(greatest(\"i2\".\"inventory_qty\", 0)/ \"pbs\".\"bundle_qty\")- floor((greatest(\"i2\".\"inventory_qty\", 0) - greatest(\"i2\".\"inventory_locked_qty\",0)) / \"pbs\".\"bundle_qty\") end AS \"inventory_locked_qty\",\n case when \"pbs\".\"bundle_qty\" <= 0 then 0 else floor(greatest(\"i2\".\"inventory_qty\", 0)/ \"pbs\".\"bundle_qty\") end AS \"inventory_qty\"\n from temp_products \"Product\" \n inner join product_bundle_settings pbs ON pbs.product_bundle_id = \"Product\".\"product_id\"\n inner join products p on p.id = pbs.product_id \n cross join fulfillment_centers fc \n inner join domains \"d2\" on \"d2\".\"ext_type\" ='warehouse' and \"fc\".\"center_id\" = \"d2\".\"subdomain\"\n left join temp_inventory i2 ON i2.product_id = pbs.product_id and \"d2\".\"id\" = \"i2\".\"domain_id\" \n where \"fc\".\"domain_id\" = $1\n order by fc.id, \"Product\".\"product_sku\", p.sku\n ) \"bundledInv\"\n group by \"domain_id\",\"fulfillment_id\",\"fulfillment_name\",\"product_id\"\n ) \"dt\" group by \"dt\".\"product_id\"\n )\n `,\n [domain.id]\n )\n\n await tx.query(`\n CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (\n SELECT \"Product\".\"product_id\" AS \"Product_id\", \"Product\".\"product_sku\" AS \"Product_sku\", \n \"Product\".\"product_name\" AS \"Product_name\", \"Product\".\"product_description\" AS \"Product_description\", \n \"Product\".\"product_bizplace_id\" AS \"Product_bizplace_id\", \n \"Product\".\"creator_id\" AS \"Product_creator_id\", \"Product\".\"updater_id\" AS \"Product_updater_id\", \n \"Bizplace\".\"name\" AS \"Bizplace_name\", \"Bizplace\".\"description\" AS \"Bizplace_description\", \"Bizplace\".\"address\" AS \"Bizplace_address\", \"Bizplace\".\"postal_code\" AS \"Bizplace_postal_code\", \n \"Bizplace\".\"latlng\" AS \"Bizplace_latlng\", \"Bizplace\".\"status\" AS \"Bizplace_status\", \"Bizplace\".\"created_at\" AS \"Bizplace_created_at\", \"Bizplace\".\"updated_at\" AS \"Bizplace_updated_at\", \n \"Bizplace\".\"domain_id\" AS \"Bizplace_domain_id\", \"Bizplace\".\"company_id\" AS \"Bizplace_company_id\", \"Bizplace\".\"creator_id\" AS \"Bizplace_creator_id\", \"Bizplace\".\"updater_id\" AS \"Bizplace_updater_id\", \n \"Creator\".\"id\" AS \"Creator_id\", \"Creator\".\"name\" AS \"Creator_name\", \"Creator\".\"description\" AS \"Creator_description\", \"Creator\".\"email\" AS \"Creator_email\",\n \"Updater\".\"id\" AS \"Updater_id\", \"Updater\".\"name\" AS \"Updater_name\", \"Updater\".\"description\" AS \"Updater_description\", \"Updater\".\"email\" AS \"Updater_email\"\n ,COALESCE(\"whInv\".\"Json_warehouseInventory\", null) AS \"Json_warehouseInventory\"\n ,COALESCE(\"mktPrd\".\"Json_marketplaceProducts\", null) AS \"Json_marketplaceProducts\"\n FROM \"temp_products\" \"Product\"\n LEFT JOIN \"bizplaces\" \"Bizplace\" ON \"Bizplace\".\"id\" = \"Product\".\"product_bizplace_id\"\n LEFT JOIN \"users\" \"Creator\" ON \"Creator\".\"id\"=\"Product\".\"creator_id\" \n LEFT JOIN \"users\" \"Updater\" ON \"Updater\".\"id\"=\"Product\".\"updater_id\"\n LEFT JOIN \"temp_json_warehouse_inventory\" \"whInv\" ON \"whInv\".\"product_id\" = \"Product\".\"product_id\"\n LEFT JOIN \"temp_json_warehouse_marketplace_products\" \"mktPrd\" ON \"mktPrd\".\"product_id\" = \"Product\".\"product_id\"\n )\n `)\n\n const offsetQuery: string = params?.pagination\n ? `OFFSET ${(params.pagination.page - 1) * params.pagination.limit} LIMIT ${params.pagination.limit}`\n : ''\n\n const total: any = await tx.query(`select count(*) from temp_warehouse_marketplace_products`)\n\n const items: any[] = await tx.query(\n `\n select * from temp_warehouse_marketplace_products ${offsetQuery}\n `\n )\n\n return {\n items: items.map((itm, index) => {\n return {\n seq: index + (params?.pagination ? (params.pagination.page - 1) * params.pagination.limit + 1 : 0),\n id: itm.Product_id,\n sku: itm.Product_sku,\n name: itm.Product_name,\n description: itm.Product_description,\n marketplaceProduct: itm.Json_marketplaceProducts\n ? itm.Json_marketplaceProducts.map(product => {\n return {\n marketplaceStore: { id: product.marketplace_store_id },\n marketplaceProductVariations: product.product_variation.map(variation => {\n return {\n id: variation.marketplace_product_variation_id,\n name: variation.name,\n qty: variation.qty,\n reserveQty: variation.reserve_qty\n }\n })\n }\n })\n : null,\n warehouseInventory: itm.Json_warehouseInventory\n ? itm.Json_warehouseInventory.map(inventory => {\n return {\n bizplace: { id: inventory.fulfillment_id, name: inventory.fulfillment_name },\n product: { id: inventory.product_id },\n qty: inventory.inventory_qty,\n lockedQty: inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0,\n remainQty:\n inventory.inventory_qty - (inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0)\n }\n })\n : null\n }\n }),\n total: total[0].count\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Query = void 0;
4
+ const shipping_providers_1 = require("./shipping-providers");
5
+ exports.Query = Object.assign({}, shipping_providers_1.shippingProviders);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/shipping-provider/index.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AAE3C,QAAA,KAAK,qBACX,sCAAiB,EACvB","sourcesContent":["import { shippingProviders } from './shipping-providers'\n\nexport const Query = {\n ...shippingProviders\n}"]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shippingProviders = void 0;
4
+ const marketplace_base_1 = require("@things-factory/marketplace-base");
5
+ const shell_1 = require("@things-factory/shell");
6
+ exports.shippingProviders = {
7
+ async shippingProviders(_, params, context) {
8
+ try {
9
+ const { domain } = context.state;
10
+ let statusFilter = ``;
11
+ if (params.statuses) {
12
+ statusFilter = `AND status in (${params.statuses.map(e => {
13
+ return `'` + e + `'`;
14
+ })})`;
15
+ }
16
+ let items = await (0, shell_1.getRepository)(marketplace_base_1.MarketplaceOrder).query(`
17
+ SELECT DISTINCT shipping_provider FROM marketplace_orders WHERE domain_id = '${domain.id}' AND marketplace_store_id = '${params.storeId}' AND shipping_provider IS NOT null AND shipping_provider != ''
18
+ ` + statusFilter);
19
+ items = items.map(e => {
20
+ const { shipping_provider: shippingProvider } = e;
21
+ return {
22
+ shippingProvider
23
+ };
24
+ });
25
+ return { items };
26
+ }
27
+ catch (error) {
28
+ throw error;
29
+ }
30
+ }
31
+ };
32
+ //# sourceMappingURL=shipping-providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shipping-providers.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/shipping-provider/shipping-providers.ts"],"names":[],"mappings":";;;AAAA,uEAAmE;AACnE,iDAAgE;AAEnD,QAAA,iBAAiB,GAAG;IAC/B,KAAK,CAAC,iBAAiB,CACrB,CAAM,EACN,MAA6D,EAC7D,OAAwB;QAExB,IAAI;YACF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;YAEhC,IAAI,YAAY,GAAG,EAAE,CAAA;YACrB,IAAI,MAAM,CAAC,QAAQ,EAAE;gBACnB,YAAY,GAAG,kBAAkB,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;oBACvD,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,CAAA;gBACtB,CAAC,CAAC,GAAG,CAAA;aACN;YAED,IAAI,KAAK,GAAU,MAAM,IAAA,qBAAa,EAAC,mCAAgB,CAAC,CAAC,KAAK,CAC5D;uFAC+E,MAAM,CAAC,EAAE,iCAAiC,MAAM,CAAC,OAAO;OACxI,GAAG,YAAY,CACf,CAAA;YAED,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBACpB,MAAM,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,GAAG,CAAC,CAAA;gBAEjD,OAAO;oBACL,gBAAgB;iBACjB,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,OAAO,EAAE,KAAK,EAAE,CAAA;SACjB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA","sourcesContent":["import { MarketplaceOrder } from '@things-factory/marketplace-base'\nimport { getRepository, ListParam } from '@things-factory/shell'\n\nexport const shippingProviders = {\n async shippingProviders(\n _: any,\n params: ListParam & { statuses?: string[]; storeId?: string },\n context: ResolverContext\n ) {\n try {\n const { domain } = context.state\n\n let statusFilter = ``\n if (params.statuses) {\n statusFilter = `AND status in (${params.statuses.map(e => {\n return `'` + e + `'`\n })})`\n }\n\n let items: any[] = await getRepository(MarketplaceOrder).query(\n `\n SELECT DISTINCT shipping_provider FROM marketplace_orders WHERE domain_id = '${domain.id}' AND marketplace_store_id = '${params.storeId}' AND shipping_provider IS NOT null AND shipping_provider != ''\n ` + statusFilter\n )\n\n items = items.map(e => {\n const { shipping_provider: shippingProvider } = e\n\n return {\n shippingProvider\n }\n })\n\n return { items }\n } catch (error) {\n throw error\n }\n }\n}\n"]}