@things-factory/warehouse-base 4.3.805 → 4.3.818
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PowrupController = void 0;
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
|
-
const biz_base_1 = require("@things-factory/biz-base");
|
|
6
5
|
const integration_powrup_1 = require("@things-factory/integration-powrup");
|
|
7
6
|
const constants_1 = require("../../constants");
|
|
8
7
|
const inventory_1 = require("../../service/inventory/inventory");
|
|
@@ -19,16 +18,31 @@ class PowrupController {
|
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
async updateStockFunction(inventories, customerDomain, user, trxMgr) {
|
|
22
|
-
|
|
21
|
+
var _a;
|
|
23
22
|
const powrup = await trxMgr
|
|
24
23
|
.getRepository(integration_powrup_1.Powrup)
|
|
25
24
|
.findOne({ where: { platform: integration_powrup_1.Platform.POWRUP, active: true } });
|
|
26
25
|
if (powrup) {
|
|
26
|
+
const customerDomainId = customerDomain === null || customerDomain === void 0 ? void 0 : customerDomain.id;
|
|
27
|
+
if (!customerDomainId)
|
|
28
|
+
return;
|
|
29
|
+
// Cache the partner resolution across inventories in a single call. Old code used
|
|
30
|
+
// Bizplace.findOne({ domain: customerDomain }), which picked any bizplace sharing
|
|
31
|
+
// the domain and leaked non-target stock to Powrup.
|
|
32
|
+
const partnerByWarehouseDomain = new Map();
|
|
27
33
|
for (let inventory of inventories) {
|
|
28
34
|
try {
|
|
29
35
|
let product = inventory.product;
|
|
30
36
|
const productDetail = inventory.productDetail;
|
|
31
37
|
const warehouseDomainId = inventory.domainId;
|
|
38
|
+
let powrupPartner = partnerByWarehouseDomain.get(warehouseDomainId);
|
|
39
|
+
if (!powrupPartner) {
|
|
40
|
+
powrupPartner = await (0, integration_powrup_1.resolveActivePowrupPartner)(trxMgr, warehouseDomainId, customerDomainId);
|
|
41
|
+
if (powrupPartner)
|
|
42
|
+
partnerByWarehouseDomain.set(warehouseDomainId, powrupPartner);
|
|
43
|
+
}
|
|
44
|
+
if (!((_a = powrupPartner === null || powrupPartner === void 0 ? void 0 : powrupPartner.bizplace) === null || _a === void 0 ? void 0 : _a.id))
|
|
45
|
+
continue;
|
|
32
46
|
let qb = trxMgr.getRepository(inventory_1.Inventory).createQueryBuilder('inv');
|
|
33
47
|
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
34
48
|
.andWhere('"inv"."domain_id" = :domainId')
|
|
@@ -39,7 +53,7 @@ class PowrupController {
|
|
|
39
53
|
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
40
54
|
.setParameters({
|
|
41
55
|
domainId: warehouseDomainId,
|
|
42
|
-
bizplaceId: bizplace.id,
|
|
56
|
+
bizplaceId: powrupPartner.bizplace.id,
|
|
43
57
|
productId: product.id,
|
|
44
58
|
productDetailId: productDetail.id,
|
|
45
59
|
status: constants_1.INVENTORY_STATUS.STORED,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powrup-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/powrup-controller.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAEtD,
|
|
1
|
+
{"version":3,"file":"powrup-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/powrup-controller.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAEtD,2EAM2C;AAE3C,+CAAiE;AACjE,iEAA6D;AAC7D,kGAA4F;AAG5F,MAAa,gBAAgB;IAC3B,KAAK,CAAC,WAAW,CACf,WAAwB,EACxB,cAAsB,EACtB,IAAW,EACX,MAAsB;QAEtB,IAAI,MAAM,EAAE;YACV,MAAM,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;SAC1E;aAAM;YACL,MAAM,IAAA,uBAAa,GAAE,CAAC,WAAW,CAAC,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AAC,CAAA;oBAEF,MAAM,kBAAkB,GAAuB,MAAM,MAAM;yBACxD,aAAa,CAAC,yCAAkB,CAAC;yBACjC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC,CAAA;oBAE7B,MAAM,UAAU,GAAU;wBACxB;4BACE,OAAO,EAAE,aAAa,CAAC,OAAO;4BAC9B,KAAK,EAAE;gCACL,aAAa,EAAE,iBAAiB,IAAI,CAAC;gCACrC,gBAAgB,EAAE,uBAAuB,GAAG,CAAC,kBAAkB,CAAC,aAAa,IAAI,CAAC,CAAC,IAAI,CAAC;gCACxF,cAAc,EAAE,CAAC;6BAClB;yBACF;qBACF,CAAA;oBAED,MAAM,8BAAS,CAAC,WAAW,CAAC,MAAM,EAAE;wBAClC,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,cAAc,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,EAAE;wBAC1E,iBAAiB;wBACjB,UAAU;qBACX,CAAC,CAAA;iBACH;gBAAC,OAAO,CAAC,EAAE;oBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;iBACf;aACF;SACF;IACH,CAAC;CACF;AAzGD,4CAyGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/warehouse-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.818",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@things-factory/biz-base": "^4.3.
|
|
27
|
-
"@things-factory/id-rule-base": "^4.3.
|
|
28
|
-
"@things-factory/integration-accounting": "^4.3.
|
|
29
|
-
"@things-factory/integration-powrup": "^4.3.
|
|
30
|
-
"@things-factory/integration-sellercraft": "^4.3.
|
|
31
|
-
"@things-factory/marketplace-base": "^4.3.
|
|
32
|
-
"@things-factory/product-base": "^4.3.
|
|
33
|
-
"@things-factory/setting-base": "^4.3.
|
|
26
|
+
"@things-factory/biz-base": "^4.3.815",
|
|
27
|
+
"@things-factory/id-rule-base": "^4.3.815",
|
|
28
|
+
"@things-factory/integration-accounting": "^4.3.815",
|
|
29
|
+
"@things-factory/integration-powrup": "^4.3.818",
|
|
30
|
+
"@things-factory/integration-sellercraft": "^4.3.815",
|
|
31
|
+
"@things-factory/marketplace-base": "^4.3.815",
|
|
32
|
+
"@things-factory/product-base": "^4.3.815",
|
|
33
|
+
"@things-factory/setting-base": "^4.3.815"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "68f211abfcbc53a014e9ad11d536680b2b86c250"
|
|
36
36
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { EntityManager, getConnection } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
Powrup,
|
|
5
|
+
PowrupAPI,
|
|
6
|
+
Platform,
|
|
7
|
+
PowrupPartnerDomain,
|
|
8
|
+
resolveActivePowrupPartner
|
|
9
|
+
} from '@things-factory/integration-powrup'
|
|
5
10
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
6
11
|
import { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'
|
|
7
12
|
import { Inventory } from '../../service/inventory/inventory'
|
|
@@ -30,17 +35,32 @@ export class PowrupController {
|
|
|
30
35
|
user?: User,
|
|
31
36
|
trxMgr?: EntityManager
|
|
32
37
|
): Promise<void> {
|
|
33
|
-
const bizplace: Bizplace = await trxMgr.getRepository(Bizplace).findOne({ domain: customerDomain })
|
|
34
38
|
const powrup: Powrup = await trxMgr
|
|
35
39
|
.getRepository(Powrup)
|
|
36
40
|
.findOne({ where: { platform: Platform.POWRUP, active: true } })
|
|
37
41
|
|
|
38
42
|
if (powrup) {
|
|
43
|
+
const customerDomainId: string = customerDomain?.id
|
|
44
|
+
if (!customerDomainId) return
|
|
45
|
+
|
|
46
|
+
// Cache the partner resolution across inventories in a single call. Old code used
|
|
47
|
+
// Bizplace.findOne({ domain: customerDomain }), which picked any bizplace sharing
|
|
48
|
+
// the domain and leaked non-target stock to Powrup.
|
|
49
|
+
const partnerByWarehouseDomain: Map<string, PowrupPartnerDomain> = new Map()
|
|
50
|
+
|
|
39
51
|
for (let inventory of inventories) {
|
|
40
52
|
try {
|
|
41
53
|
let product: Product = inventory.product
|
|
42
54
|
const productDetail: ProductDetail = inventory.productDetail
|
|
43
55
|
const warehouseDomainId: string = inventory.domainId
|
|
56
|
+
|
|
57
|
+
let powrupPartner = partnerByWarehouseDomain.get(warehouseDomainId)
|
|
58
|
+
if (!powrupPartner) {
|
|
59
|
+
powrupPartner = await resolveActivePowrupPartner(trxMgr, warehouseDomainId, customerDomainId)
|
|
60
|
+
if (powrupPartner) partnerByWarehouseDomain.set(warehouseDomainId, powrupPartner)
|
|
61
|
+
}
|
|
62
|
+
if (!powrupPartner?.bizplace?.id) continue
|
|
63
|
+
|
|
44
64
|
let qb = trxMgr.getRepository(Inventory).createQueryBuilder('inv')
|
|
45
65
|
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
46
66
|
.andWhere('"inv"."domain_id" = :domainId')
|
|
@@ -51,7 +71,7 @@ export class PowrupController {
|
|
|
51
71
|
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
52
72
|
.setParameters({
|
|
53
73
|
domainId: warehouseDomainId,
|
|
54
|
-
bizplaceId: bizplace.id,
|
|
74
|
+
bizplaceId: powrupPartner.bizplace.id,
|
|
55
75
|
productId: product.id,
|
|
56
76
|
productDetailId: productDetail.id,
|
|
57
77
|
status: INVENTORY_STATUS.STORED,
|