@things-factory/operato-hub 4.3.290 → 4.3.292

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.
@@ -7,13 +7,15 @@ const fetch_sync_invoices_1 = require("./fetch-sync-invoices");
7
7
  const fetch_sync_products_1 = require("./fetch-sync-products");
8
8
  const fetch_sync_purchase_orders_1 = require("./fetch-sync-purchase-orders");
9
9
  const get_lmd_awb_1 = require("./get-lmd-awb");
10
- const powrup_pack_order_1 = require("./powrup-pack-order");
11
10
  const powrup_get_tracking_no_1 = require("./powrup-get-tracking-no");
11
+ const powrup_pack_order_1 = require("./powrup-pack-order");
12
12
  const sellercraft_pack_marketplace_order_1 = require("./sellercraft-pack-marketplace-order");
13
+ const sync_all_products_to_powrup_1 = require("./sync-all-products-to-powrup");
13
14
  const sync_all_products_to_sellercraft_1 = require("./sync-all-products-to-sellercraft");
14
15
  const sync_products_from_account_1 = require("./sync-products-from-account");
15
16
  const sync_products_to_account_1 = require("./sync-products-to-account");
17
+ const sync_products_to_powrup_1 = require("./sync-products-to-powrup");
16
18
  const sync_products_to_sellercraft_1 = require("./sync-products-to-sellercraft");
17
19
  exports.Query = Object.assign(Object.assign(Object.assign({}, fetch_sync_products_1.fetchSyncProductsResolver), fetch_sync_purchase_orders_1.fetchSyncPurchaseOrdersResolver), fetch_sync_invoices_1.fetchSyncInvoicesResolver);
18
- exports.Mutation = Object.assign(Object.assign(Object.assign(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), get_lmd_awb_1.getLmdAwbResolver), powrup_pack_order_1.powrupPackOrderResolver), powrup_get_tracking_no_1.powrupGetTrackingNoResolver);
20
+ exports.Mutation = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, sync_products_to_sellercraft_1.syncProductsToSellercraftResolver), sync_products_to_powrup_1.syncProductsToPowrupResolver), sync_products_from_account_1.syncProductsFromAccountResolver), sync_products_to_account_1.syncProductsToAccountResolver), sync_all_products_to_sellercraft_1.syncAllProductsToSellercraftResolver), sync_all_products_to_powrup_1.syncAllProductsToPowrupResolver), sellercraft_pack_marketplace_order_1.sellercraftPackMarketplaceOrderResolver), create_dat_shipments_1.createDatShipments), auto_update_all_marketplace_product_variation_quantity_1.autoUpdateAllMarketplaceProductVariationQuantityResolver), get_lmd_awb_1.getLmdAwbResolver), powrup_pack_order_1.powrupPackOrderResolver), powrup_get_tracking_no_1.powrupGetTrackingNoResolver);
19
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/index.ts"],"names":[],"mappings":";;;AAAA,qIAAmI;AACnI,iEAA2D;AAC3D,+DAAiE;AACjE,+DAAiE;AACjE,6EAA8E;AAC9E,+CAAiD;AACjD,2DAA6D;AAC7D,qEAAsE;AACtE,6FAA8F;AAC9F,yFAAyF;AACzF,6EAA8E;AAC9E,yEAA0E;AAC1E,iFAAkF;AAErE,QAAA,KAAK,iDACb,+CAAyB,GACzB,4DAA+B,GAC/B,+CAAyB,EAC7B;AAEY,QAAA,QAAQ,mJAChB,gEAAiC,GACjC,4DAA+B,GAC/B,wDAA6B,GAC7B,uEAAoC,GACpC,4EAAuC,GACvC,yCAAkB,GAClB,iHAAwD,GACxD,+BAAiB,GACjB,2CAAuB,GACvB,oDAA2B,EAC/B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/index.ts"],"names":[],"mappings":";;;AAAA,qIAAoI;AACpI,iEAA4D;AAC5D,+DAAkE;AAClE,+DAAkE;AAClE,6EAA+E;AAC/E,+CAAkD;AAClD,qEAAuE;AACvE,2DAA8D;AAC9D,6FAA+F;AAC/F,+EAAgF;AAChF,yFAA0F;AAC1F,6EAA+E;AAC/E,yEAA2E;AAC3E,uEAAyE;AACzE,iFAAmF;AAEtE,QAAA,KAAK,iDACb,+CAAyB,GACzB,4DAA+B,GAC/B,+CAAyB,EAC7B;AAEY,QAAA,QAAQ,+KAChB,gEAAiC,GACjC,sDAA4B,GAC5B,4DAA+B,GAC/B,wDAA6B,GAC7B,uEAAoC,GACpC,6DAA+B,GAC/B,4EAAuC,GACvC,yCAAkB,GAClB,iHAAwD,GACxD,+BAAiB,GACjB,2CAAuB,GACvB,oDAA2B,EAC/B"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncAllProductsToPowrupResolver = void 0;
4
+ const typeorm_1 = require("typeorm");
5
+ const integration_powrup_1 = require("@things-factory/integration-powrup");
6
+ const sync_products_to_powrup_1 = require("./sync-products-to-powrup");
7
+ exports.syncAllProductsToPowrupResolver = {
8
+ async syncAllProductsToPowrup(_, {}, context) {
9
+ const { user } = context.state;
10
+ try {
11
+ await (0, typeorm_1.getConnection)().transaction(async (tx) => {
12
+ // const qb = tx
13
+ // .getRepository(Bizplace)
14
+ // .createQueryBuilder('bizplace')
15
+ // .innerJoinAndSelect('bizplace.domain', 'domain')
16
+ // .where('bizplace.powrupSync = :powrupSync', { powrupSync: true })
17
+ // .andWhere('domain.extType ISNULL')
18
+ // const bizplaces: Bizplace[] = await qb.getMany()
19
+ let powrupPartners = await tx
20
+ .getRepository(integration_powrup_1.PowrupPartnerDomain)
21
+ .find({ where: { active: true } });
22
+ for (const powrupPartner of powrupPartners) {
23
+ await sync_products_to_powrup_1.syncProductsToPowrupResolver.syncProductsToPowrup(null, { powrupPartnerId: powrupPartner.id }, context);
24
+ }
25
+ });
26
+ }
27
+ catch (e) {
28
+ console.log(e);
29
+ }
30
+ }
31
+ };
32
+ //# sourceMappingURL=sync-all-products-to-powrup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-all-products-to-powrup.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/sync-all-products-to-powrup.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAGtD,2EAAwE;AAExE,uEAAoF;AAEvE,QAAA,+BAA+B,GAAG;IAC7C,KAAK,CAAC,uBAAuB,CAAC,CAAM,EAAE,EAAE,EAAE,OAAY;QACpD,MAAM,EAAE,IAAI,EAAE,GAAsC,OAAO,CAAC,KAAK,CAAA;QACjE,IAAI;YACF,MAAM,IAAA,uBAAa,GAAE,CAAC,WAAW,CAAC,KAAK,EAAC,EAAE,EAAC,EAAE;gBAC3C,gBAAgB;gBAChB,6BAA6B;gBAC7B,oCAAoC;gBACpC,qDAAqD;gBACrD,sEAAsE;gBACtE,uCAAuC;gBAEvC,mDAAmD;gBAEnD,IAAI,cAAc,GAA0B,MAAM,EAAE;qBACjD,aAAa,CAAC,wCAAmB,CAAC;qBAClC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;gBAEpC,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;oBAC1C,MAAM,sDAAQ,CAAC,oBAAoB,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,aAAa,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;iBAC1F;YACH,CAAC,CAAC,CAAA;SACH;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;SACf;IACH,CAAC;CACF,CAAA"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncProductsToPowrupResolver = void 0;
4
+ const auth_base_1 = require("@things-factory/auth-base");
5
+ const biz_base_1 = require("@things-factory/biz-base");
6
+ const env_1 = require("@things-factory/env");
7
+ const integration_powrup_1 = require("@things-factory/integration-powrup");
8
+ const warehouse_base_1 = require("@things-factory/warehouse-base");
9
+ exports.syncProductsToPowrupResolver = {
10
+ async syncProductsToPowrup(_, { powrupPartnerId }, context) {
11
+ var _a;
12
+ try {
13
+ const { tx } = context.state;
14
+ let page = 0;
15
+ let hasMorePage = true;
16
+ const limit = 50;
17
+ let powrupPartner = await tx
18
+ .getRepository(integration_powrup_1.PowrupPartnerDomain)
19
+ .findOne({ where: { id: powrupPartnerId }, relations: ['domain', 'bizplace', 'bizplace.domain'] });
20
+ const companyBizplace = await (0, biz_base_1.getCompanyBizplace)(null, null, powrupPartner.bizplace.id, tx);
21
+ const application = await tx
22
+ .getRepository(auth_base_1.Application)
23
+ .findOne({ where: { domain: companyBizplace.domain, status: 'ACTIVE', type: auth_base_1.ApplicationType.POWRUP } });
24
+ if (application) {
25
+ const powrup = await tx
26
+ .getRepository(integration_powrup_1.Powrup)
27
+ .findOne({ where: { platform: integration_powrup_1.Platform.POWRUP, active: true } });
28
+ await tx.query(`
29
+ create temp table temp_warehouse_product_inventory ON COMMIT DROP as (
30
+ select pd.ref_code, pd.packing_size, coalesce(src.qty, 0) as available_qty, coalesce(src.qty - src."remain_qty", 0) as reserved_qty, coalesce(src."remain_qty",0) as remain_qty,
31
+ coalesce(src.reserve_qty,0) as buffer_qty
32
+ from bizplaces b
33
+ inner join companies c on c.id = b.company_id
34
+ inner join domains d on d.id = c.domain_id
35
+ inner join products p on p.domain_id = b.domain_id or p.domain_id = c.domain_id
36
+ inner join product_details pd on pd.product_id = p.id
37
+ left join (
38
+ select wboi.*, invReserve.qty as reserve_qty from warehouse_bizplace_onhand_inventories wboi
39
+ inner join domains d on d.id = wboi."domain_id"
40
+ left join (
41
+ select product_id, sum(i.qty) as qty from inventories i
42
+ inner join locations l2 on l2.id = i.location_id
43
+ where i.bizplace_id = $1 and i.domain_id = $2 and l2."type" = $3
44
+ group by i.product_id
45
+ ) invReserve on invReserve.product_id = wboi.product_id
46
+ where wboi."bizplace_id" = $1 and wboi."domain_id" = $2 and wboi."group_type" = 'SINGLE'
47
+ ) src on src."product_id" = pd."product_id"
48
+ and src."packing_type" = pd."packing_type"
49
+ and src."packing_size" = pd."packing_size"
50
+ and src."uom" = pd."uom"
51
+ where b.id = $1
52
+ )
53
+ `, [powrupPartner.bizplace.id, powrupPartner.domain.id, warehouse_base_1.LOCATION_TYPE.RESERVE]);
54
+ let total = await tx.query(`
55
+ select count(*) from temp_warehouse_product_inventory
56
+ `);
57
+ while (hasMorePage) {
58
+ hasMorePage = false;
59
+ try {
60
+ const items = await tx.query(`
61
+ select * from temp_warehouse_product_inventory limit $1 offset $2
62
+ `, [limit, page * limit]);
63
+ let powrupInv = [];
64
+ items.map(async (item) => {
65
+ powrupInv.push({
66
+ refCode: item.ref_code,
67
+ stock: {
68
+ quantityTotal: item.available_qty < 0 ? 0 : item.available_qty,
69
+ quantityReserved: item.reserved_qty < 0 ? 0 : item.reserved_qty,
70
+ quantityBuffer: item.buffer_qty
71
+ }
72
+ });
73
+ });
74
+ const delay = (ms) => {
75
+ return new Promise(resolve => setTimeout(resolve, ms));
76
+ };
77
+ await delay(500);
78
+ page++;
79
+ hasMorePage = (((_a = total[0]) === null || _a === void 0 ? void 0 : _a.count) || 0) > page * limit;
80
+ await integration_powrup_1.PowrupAPI.updateStock(powrup, {
81
+ context: { state: { domain: powrupPartner.bizplace.domain || null, user: null } },
82
+ warehouseDomainId: powrupPartner.domain.id,
83
+ powrupInv
84
+ });
85
+ }
86
+ catch (e) {
87
+ env_1.logger.error(`[syncProductsToPowrupResolver] bizplaceId:${powrupPartner.bizplace.id} domainId:${powrupPartner.domain.id} page:${page} - ${e}`);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ catch (e) {
93
+ env_1.logger.error(`syncProductsToPowrupResolver: ${e}`);
94
+ }
95
+ }
96
+ };
97
+ //# sourceMappingURL=sync-products-to-powrup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-products-to-powrup.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/synchronization/sync-products-to-powrup.ts"],"names":[],"mappings":"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"}
@@ -14,9 +14,11 @@ exports.Query = `
14
14
  `;
15
15
  exports.Mutation = `
16
16
  syncProductsToSellercraft(sellercraftId: String!, fulfillmentCenterId: String!): Boolean @transaction
17
+ syncProductsToPowrup(powrupPartnerId: String!): Boolean @transaction
17
18
  syncProductsFromAccount(accountId: String!, bizplaceId: String!): Boolean @transaction
18
19
  syncProductsToAccount(accountId: String!, bizplaceId: String!): Boolean @transaction
19
20
  syncAllProductsToSellercraft: Boolean @transaction
21
+ syncAllProductsToPowrup: Boolean @transaction
20
22
  sellercraftPackMarketplaceOrder: Boolean @transaction
21
23
  powrupPackOrder: Boolean @transaction
22
24
  powrupGetTrackingNo: Boolean @transaction
@@ -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;;;;;;;;;;;;CAYrC,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;;;;;;;;;;;;;;CAcrC,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.290",
3
+ "version": "4.3.292",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -77,22 +77,22 @@
77
77
  "@things-factory/i18n-base": "^4.3.281",
78
78
  "@things-factory/import-ui": "^4.3.281",
79
79
  "@things-factory/import-ui-excel": "^4.3.281",
80
- "@things-factory/integration-accounting": "^4.3.281",
80
+ "@things-factory/integration-accounting": "^4.3.291",
81
81
  "@things-factory/integration-fulfillment": "^4.3.281",
82
82
  "@things-factory/integration-lmd": "^4.3.286",
83
83
  "@things-factory/integration-marketplace": "^4.3.286",
84
84
  "@things-factory/integration-pos": "^4.3.281",
85
- "@things-factory/integration-powrup": "^4.3.286",
85
+ "@things-factory/integration-powrup": "^4.3.292",
86
86
  "@things-factory/integration-sellercraft": "^4.3.286",
87
87
  "@things-factory/integration-sftp": "^4.3.281",
88
88
  "@things-factory/lite-menu": "^4.3.281",
89
- "@things-factory/marketplace-base": "^4.3.286",
89
+ "@things-factory/marketplace-base": "^4.3.291",
90
90
  "@things-factory/more-ui": "^4.3.281",
91
91
  "@things-factory/notification": "^4.3.281",
92
92
  "@things-factory/pdf": "^4.3.281",
93
- "@things-factory/product-ui": "^4.3.284",
93
+ "@things-factory/product-ui": "^4.3.291",
94
94
  "@things-factory/resource-ui": "^4.3.281",
95
- "@things-factory/sales-base": "^4.3.290",
95
+ "@things-factory/sales-base": "^4.3.292",
96
96
  "@things-factory/scene-data-transform": "^4.3.281",
97
97
  "@things-factory/scene-excel": "^4.3.281",
98
98
  "@things-factory/scene-firebase": "^4.3.281",
@@ -107,8 +107,8 @@
107
107
  "@things-factory/setting-ui": "^4.3.281",
108
108
  "@things-factory/shell": "^4.3.281",
109
109
  "@things-factory/system-ui": "^4.3.281",
110
- "@things-factory/warehouse-base": "^4.3.290",
111
- "@things-factory/worksheet-base": "^4.3.290",
110
+ "@things-factory/warehouse-base": "^4.3.292",
111
+ "@things-factory/worksheet-base": "^4.3.292",
112
112
  "cron-parser": "^4.7.0",
113
113
  "koa2-swagger-ui": "^5.0.2",
114
114
  "swagger-jsdoc": "^5.0.0",
@@ -120,5 +120,5 @@
120
120
  "resolutions": {
121
121
  "core-js": "^3.16.0"
122
122
  },
123
- "gitHead": "345e8a252ebc6b013b2927dca0e9e3bce749f031"
123
+ "gitHead": "3b2f8ac63dbe662c56471717a635e12d1a1a14d6"
124
124
  }
@@ -1,16 +1,18 @@
1
- import { autoUpdateAllMarketplaceProductVariationQuantityResolver } from './auto-update-all-marketplace-product-variation-quantity'
2
- import { createDatShipments } from './create-dat-shipments'
3
- import { fetchSyncInvoicesResolver } from './fetch-sync-invoices'
4
- import { fetchSyncProductsResolver } from './fetch-sync-products'
5
- import { fetchSyncPurchaseOrdersResolver } from './fetch-sync-purchase-orders'
6
- import { getLmdAwbResolver } from './get-lmd-awb'
7
- import { powrupPackOrderResolver } from './powrup-pack-order'
8
- import { powrupGetTrackingNoResolver } from './powrup-get-tracking-no'
9
- import { sellercraftPackMarketplaceOrderResolver } from './sellercraft-pack-marketplace-order'
10
- import { syncAllProductsToSellercraftResolver } from './sync-all-products-to-sellercraft'
11
- import { syncProductsFromAccountResolver } from './sync-products-from-account'
12
- import { syncProductsToAccountResolver } from './sync-products-to-account'
13
- import { syncProductsToSellercraftResolver } from './sync-products-to-sellercraft'
1
+ import { autoUpdateAllMarketplaceProductVariationQuantityResolver } from './auto-update-all-marketplace-product-variation-quantity';
2
+ import { createDatShipments } from './create-dat-shipments';
3
+ import { fetchSyncInvoicesResolver } from './fetch-sync-invoices';
4
+ import { fetchSyncProductsResolver } from './fetch-sync-products';
5
+ import { fetchSyncPurchaseOrdersResolver } from './fetch-sync-purchase-orders';
6
+ import { getLmdAwbResolver } from './get-lmd-awb';
7
+ import { powrupGetTrackingNoResolver } from './powrup-get-tracking-no';
8
+ import { powrupPackOrderResolver } from './powrup-pack-order';
9
+ import { sellercraftPackMarketplaceOrderResolver } from './sellercraft-pack-marketplace-order';
10
+ import { syncAllProductsToPowrupResolver } from './sync-all-products-to-powrup';
11
+ import { syncAllProductsToSellercraftResolver } from './sync-all-products-to-sellercraft';
12
+ import { syncProductsFromAccountResolver } from './sync-products-from-account';
13
+ import { syncProductsToAccountResolver } from './sync-products-to-account';
14
+ import { syncProductsToPowrupResolver } from './sync-products-to-powrup';
15
+ import { syncProductsToSellercraftResolver } from './sync-products-to-sellercraft';
14
16
 
15
17
  export const Query = {
16
18
  ...fetchSyncProductsResolver,
@@ -20,9 +22,11 @@ export const Query = {
20
22
 
21
23
  export const Mutation = {
22
24
  ...syncProductsToSellercraftResolver,
25
+ ...syncProductsToPowrupResolver,
23
26
  ...syncProductsFromAccountResolver,
24
27
  ...syncProductsToAccountResolver,
25
28
  ...syncAllProductsToSellercraftResolver,
29
+ ...syncAllProductsToPowrupResolver,
26
30
  ...sellercraftPackMarketplaceOrderResolver,
27
31
  ...createDatShipments,
28
32
  ...autoUpdateAllMarketplaceProductVariationQuantityResolver,
@@ -0,0 +1,34 @@
1
+ import { EntityManager, getConnection } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { PowrupPartnerDomain } from '@things-factory/integration-powrup'
5
+
6
+ import { syncProductsToPowrupResolver as resolver } from './sync-products-to-powrup'
7
+
8
+ export const syncAllProductsToPowrupResolver = {
9
+ async syncAllProductsToPowrup(_: any, {}, context: any): Promise<void> {
10
+ const { user }: { user: User; tx: EntityManager } = context.state
11
+ try {
12
+ await getConnection().transaction(async tx => {
13
+ // const qb = tx
14
+ // .getRepository(Bizplace)
15
+ // .createQueryBuilder('bizplace')
16
+ // .innerJoinAndSelect('bizplace.domain', 'domain')
17
+ // .where('bizplace.powrupSync = :powrupSync', { powrupSync: true })
18
+ // .andWhere('domain.extType ISNULL')
19
+
20
+ // const bizplaces: Bizplace[] = await qb.getMany()
21
+
22
+ let powrupPartners: PowrupPartnerDomain[] = await tx
23
+ .getRepository(PowrupPartnerDomain)
24
+ .find({ where: { active: true } })
25
+
26
+ for (const powrupPartner of powrupPartners) {
27
+ await resolver.syncProductsToPowrup(null, { powrupPartnerId: powrupPartner.id }, context)
28
+ }
29
+ })
30
+ } catch (e) {
31
+ console.log(e)
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,114 @@
1
+ import { EntityManager } from 'typeorm'
2
+
3
+ import { Application, ApplicationType } from '@things-factory/auth-base'
4
+ import { Bizplace, getCompanyBizplace } from '@things-factory/biz-base'
5
+ import { logger } from '@things-factory/env'
6
+ import { Platform, Powrup, PowrupAPI, PowrupPartnerDomain } from '@things-factory/integration-powrup'
7
+ import { LOCATION_TYPE } from '@things-factory/warehouse-base'
8
+
9
+ export const syncProductsToPowrupResolver = {
10
+ async syncProductsToPowrup(_: void, { powrupPartnerId }: { powrupPartnerId: String }, context: any): Promise<void> {
11
+ try {
12
+ const { tx }: { tx: EntityManager } = context.state
13
+
14
+ let page: number = 0
15
+ let hasMorePage: boolean = true
16
+ const limit: number = 50
17
+
18
+ let powrupPartner: PowrupPartnerDomain = await tx
19
+ .getRepository(PowrupPartnerDomain)
20
+ .findOne({ where: { id: powrupPartnerId }, relations: ['domain', 'bizplace', 'bizplace.domain'] })
21
+
22
+ const companyBizplace: Bizplace = await getCompanyBizplace(null, null, powrupPartner.bizplace.id, tx)
23
+ const application: Application = await tx
24
+ .getRepository(Application)
25
+ .findOne({ where: { domain: companyBizplace.domain, status: 'ACTIVE', type: ApplicationType.POWRUP } })
26
+
27
+ if (application) {
28
+ const powrup: Powrup = await tx
29
+ .getRepository(Powrup)
30
+ .findOne({ where: { platform: Platform.POWRUP, active: true } })
31
+
32
+ await tx.query(
33
+ `
34
+ create temp table temp_warehouse_product_inventory ON COMMIT DROP as (
35
+ select pd.ref_code, pd.packing_size, coalesce(src.qty, 0) as available_qty, coalesce(src.qty - src."remain_qty", 0) as reserved_qty, coalesce(src."remain_qty",0) as remain_qty,
36
+ coalesce(src.reserve_qty,0) as buffer_qty
37
+ from bizplaces b
38
+ inner join companies c on c.id = b.company_id
39
+ inner join domains d on d.id = c.domain_id
40
+ inner join products p on p.domain_id = b.domain_id or p.domain_id = c.domain_id
41
+ inner join product_details pd on pd.product_id = p.id
42
+ left join (
43
+ select wboi.*, invReserve.qty as reserve_qty from warehouse_bizplace_onhand_inventories wboi
44
+ inner join domains d on d.id = wboi."domain_id"
45
+ left join (
46
+ select product_id, sum(i.qty) as qty from inventories i
47
+ inner join locations l2 on l2.id = i.location_id
48
+ where i.bizplace_id = $1 and i.domain_id = $2 and l2."type" = $3
49
+ group by i.product_id
50
+ ) invReserve on invReserve.product_id = wboi.product_id
51
+ where wboi."bizplace_id" = $1 and wboi."domain_id" = $2 and wboi."group_type" = 'SINGLE'
52
+ ) src on src."product_id" = pd."product_id"
53
+ and src."packing_type" = pd."packing_type"
54
+ and src."packing_size" = pd."packing_size"
55
+ and src."uom" = pd."uom"
56
+ where b.id = $1
57
+ )
58
+ `,
59
+ [powrupPartner.bizplace.id, powrupPartner.domain.id, LOCATION_TYPE.RESERVE]
60
+ )
61
+
62
+ let total = await tx.query(`
63
+ select count(*) from temp_warehouse_product_inventory
64
+ `)
65
+
66
+ while (hasMorePage) {
67
+ hasMorePage = false
68
+ try {
69
+ const items = await tx.query(
70
+ `
71
+ select * from temp_warehouse_product_inventory limit $1 offset $2
72
+ `,
73
+ [limit, page * limit]
74
+ )
75
+
76
+ let powrupInv: any[] = []
77
+
78
+ items.map(async item => {
79
+ powrupInv.push({
80
+ refCode: item.ref_code,
81
+ stock: {
82
+ quantityTotal: item.available_qty < 0 ? 0 : item.available_qty,
83
+ quantityReserved: item.reserved_qty < 0 ? 0 : item.reserved_qty,
84
+ quantityBuffer: item.buffer_qty
85
+ }
86
+ })
87
+ })
88
+
89
+ const delay = (ms: number) => {
90
+ return new Promise(resolve => setTimeout(resolve, ms))
91
+ }
92
+
93
+ await delay(500)
94
+
95
+ page++
96
+ hasMorePage = (total[0]?.count || 0) > page * limit
97
+
98
+ await PowrupAPI.updateStock(powrup, {
99
+ context: { state: { domain: powrupPartner.bizplace.domain || null, user: null } },
100
+ warehouseDomainId: powrupPartner.domain.id,
101
+ powrupInv
102
+ })
103
+ } catch (e) {
104
+ logger.error(
105
+ `[syncProductsToPowrupResolver] bizplaceId:${powrupPartner.bizplace.id} domainId:${powrupPartner.domain.id} page:${page} - ${e}`
106
+ )
107
+ }
108
+ }
109
+ }
110
+ } catch (e) {
111
+ logger.error(`syncProductsToPowrupResolver: ${e}`)
112
+ }
113
+ }
114
+ }
@@ -13,9 +13,11 @@ export const Query = /* GraphQL */ `
13
13
 
14
14
  export const Mutation = /* GraphQL */ `
15
15
  syncProductsToSellercraft(sellercraftId: String!, fulfillmentCenterId: String!): Boolean @transaction
16
+ syncProductsToPowrup(powrupPartnerId: String!): Boolean @transaction
16
17
  syncProductsFromAccount(accountId: String!, bizplaceId: String!): Boolean @transaction
17
18
  syncProductsToAccount(accountId: String!, bizplaceId: String!): Boolean @transaction
18
19
  syncAllProductsToSellercraft: Boolean @transaction
20
+ syncAllProductsToPowrup: Boolean @transaction
19
21
  sellercraftPackMarketplaceOrder: Boolean @transaction
20
22
  powrupPackOrder: Boolean @transaction
21
23
  powrupGetTrackingNo: Boolean @transaction