@things-factory/warehouse-base 3.8.23 → 3.8.27
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SellercraftController = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
4
|
const integration_sellercraft_1 = require("@things-factory/integration-sellercraft");
|
|
6
5
|
const constants_1 = require("../../constants");
|
|
7
6
|
const inventory_1 = require("../../service/inventory/inventory");
|
|
@@ -10,38 +9,53 @@ class SellercraftController extends warehouse_controller_1.WarehouseController {
|
|
|
10
9
|
async updateSellercraftStock(sellercraft, inventory) {
|
|
11
10
|
let product = inventory.product;
|
|
12
11
|
const productDetails = product.productDetails;
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
let qb = await this.trxMgr.getRepository(inventory_1.Inventory).createQueryBuilder('inv');
|
|
13
|
+
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
14
|
+
.andWhere('"inv"."domain_id" = :domainId')
|
|
15
|
+
.andWhere('"inv"."product_id" = :productId')
|
|
16
|
+
.andWhere('"inv"."status" != :status')
|
|
17
|
+
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
18
|
+
.setParameters({
|
|
19
|
+
domainId: this.domain.id,
|
|
20
|
+
productId: product.id,
|
|
21
|
+
status: constants_1.INVENTORY_STATUS.TERMINATED,
|
|
22
|
+
locationTypes: [constants_1.LOCATION_TYPE.QUARANTINE, constants_1.LOCATION_TYPE.RESERVE]
|
|
15
23
|
});
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
let inventories = await qb.getMany();
|
|
25
|
+
let defaultProductDetail = product.productDetails.find(productDetail => productDetail.isDefault);
|
|
26
|
+
let inventoryTotalQty = 0;
|
|
27
|
+
if ((inventories === null || inventories === void 0 ? void 0 : inventories.length) > 0) {
|
|
28
|
+
const sellercraftInvs = await Promise.all(inventories.map(async (inventory) => {
|
|
29
|
+
const inventoryPackingType = inventory.packingType;
|
|
30
|
+
let packingSize = 1;
|
|
31
|
+
if (inventoryPackingType !== defaultProductDetail.packingType) {
|
|
32
|
+
const unmatchingProductDetail = product.productDetails.find(productDetail => productDetail.packingType === inventoryPackingType);
|
|
33
|
+
packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail);
|
|
34
|
+
}
|
|
35
|
+
return { quantity: inventory.qty * packingSize - inventory.lockedQty * packingSize };
|
|
36
|
+
}));
|
|
37
|
+
inventoryTotalQty = sellercraftInvs.reduce((total, currentValue) => {
|
|
38
|
+
total += currentValue.quantity;
|
|
39
|
+
return total;
|
|
40
|
+
}, 0);
|
|
41
|
+
}
|
|
42
|
+
const sellercraftInv = [
|
|
43
|
+
{
|
|
44
|
+
sku: product.sku,
|
|
45
|
+
gtin: defaultProductDetail.gtin,
|
|
46
|
+
stock: {
|
|
47
|
+
quantity: inventoryTotalQty,
|
|
48
|
+
unit_of_measure: 'EA'
|
|
49
|
+
},
|
|
50
|
+
package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
|
|
51
|
+
package_dimensions: {
|
|
52
|
+
length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
|
|
53
|
+
width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
|
|
54
|
+
height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
|
|
55
|
+
}
|
|
24
56
|
}
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
const totalQty = sellercraftInvs.reduce((total, currentValue) => {
|
|
28
|
-
total += currentValue.quantity;
|
|
29
|
-
return total;
|
|
30
|
-
}, 0);
|
|
31
|
-
const sellercraftInv = {
|
|
32
|
-
accountId: sellercraft.accountId,
|
|
33
|
-
sku: product.sku,
|
|
34
|
-
uom: 'EA',
|
|
35
|
-
quantity: totalQty,
|
|
36
|
-
gtin: defaultProductDetail.gtin,
|
|
37
|
-
weight: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
|
|
38
|
-
packageDimension: {
|
|
39
|
-
length: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
|
|
40
|
-
width: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
|
|
41
|
-
height: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
await integration_sellercraft_1.SellercraftAPI.updateProduct(sellercraft, { sellercraftInv });
|
|
57
|
+
];
|
|
58
|
+
await integration_sellercraft_1.SellercraftAPI.updateProduct(sellercraft, { accountId: sellercraft.accountId, sellercraftInv });
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
61
|
exports.SellercraftController = SellercraftController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sellercraft-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/sellercraft-controller.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"sellercraft-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/sellercraft-controller.ts"],"names":[],"mappings":";;;AAAA,qFAAqF;AAGrF,+CAAiE;AACjE,iEAA6D;AAC7D,kEAA6D;AAE7D,MAAa,qBAAsB,SAAQ,0CAAmB;IAC5D,KAAK,CAAC,sBAAsB,CAAC,WAAwB,EAAE,SAAoB;QACzE,IAAI,OAAO,GAAY,SAAS,CAAC,OAAO,CAAA;QACxC,MAAM,cAAc,GAAoB,OAAO,CAAC,cAAc,CAAA;QAE9D,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,qBAAS,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;QAC7E,EAAE,CAAC,iBAAiB,CAAC,cAA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"version": "3.8.
|
|
3
|
+
"version": "3.8.27",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/biz-base": "^3.8.
|
|
27
|
+
"@things-factory/biz-base": "^3.8.26",
|
|
28
28
|
"@things-factory/id-rule-base": "^3.8.0",
|
|
29
|
-
"@things-factory/integration-sellercraft": "^3.8.
|
|
30
|
-
"@things-factory/marketplace-base": "^3.8.
|
|
31
|
-
"@things-factory/product-base": "^3.8.
|
|
29
|
+
"@things-factory/integration-sellercraft": "^3.8.27",
|
|
30
|
+
"@things-factory/marketplace-base": "^3.8.27",
|
|
31
|
+
"@things-factory/product-base": "^3.8.26",
|
|
32
32
|
"@things-factory/setting-base": "^3.8.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "6e1de7441570bf9d6f42324f7d1c96e42881b46e"
|
|
35
35
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Equal, Not } from 'typeorm'
|
|
2
|
-
|
|
3
1
|
import { Sellercraft, SellercraftAPI } from '@things-factory/integration-sellercraft'
|
|
4
2
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
5
3
|
|
|
6
|
-
import { INVENTORY_STATUS } from '../../constants'
|
|
4
|
+
import { INVENTORY_STATUS, LOCATION_TYPE } from '../../constants'
|
|
7
5
|
import { Inventory } from '../../service/inventory/inventory'
|
|
8
6
|
import { WarehouseController } from '../warehouse-controller'
|
|
9
7
|
|
|
@@ -11,48 +9,66 @@ export class SellercraftController extends WarehouseController {
|
|
|
11
9
|
async updateSellercraftStock(sellercraft: Sellercraft, inventory: Inventory): Promise<void> {
|
|
12
10
|
let product: Product = inventory.product
|
|
13
11
|
const productDetails: ProductDetail[] = product.productDetails
|
|
14
|
-
const inventories: Inventory[] = await this.trxMgr.getRepository(Inventory).find({
|
|
15
|
-
where: { domain: this.domain, product, status: Not(Equal(INVENTORY_STATUS.TERMINATED)) }
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
let defaultProductDetail: ProductDetail
|
|
19
|
-
const sellercraftInvs: any[] = await Promise.all(
|
|
20
|
-
inventories.map(async (inventory: Inventory) => {
|
|
21
|
-
const inventoryPackingType: string = inventory.packingType
|
|
22
|
-
defaultProductDetail = product.productDetails.find(productDetail => productDetail.isDefault)
|
|
23
|
-
|
|
24
|
-
let packingSize: number = 1
|
|
25
|
-
if (inventoryPackingType !== defaultProductDetail.packingType) {
|
|
26
|
-
const unmatchingProductDetail: ProductDetail = product.productDetails.find(
|
|
27
|
-
productDetail => productDetail.packingType === inventoryPackingType
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail)
|
|
31
|
-
}
|
|
32
12
|
|
|
33
|
-
|
|
13
|
+
let qb = await this.trxMgr.getRepository(Inventory).createQueryBuilder('inv')
|
|
14
|
+
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
15
|
+
.andWhere('"inv"."domain_id" = :domainId')
|
|
16
|
+
.andWhere('"inv"."product_id" = :productId')
|
|
17
|
+
.andWhere('"inv"."status" != :status')
|
|
18
|
+
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
19
|
+
.setParameters({
|
|
20
|
+
domainId: this.domain.id,
|
|
21
|
+
productId: product.id,
|
|
22
|
+
status: INVENTORY_STATUS.TERMINATED,
|
|
23
|
+
locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
34
24
|
})
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
|
|
26
|
+
let inventories: Inventory[] = await qb.getMany()
|
|
27
|
+
|
|
28
|
+
let defaultProductDetail: ProductDetail = product.productDetails.find(productDetail => productDetail.isDefault)
|
|
29
|
+
let inventoryTotalQty: number = 0
|
|
30
|
+
|
|
31
|
+
if (inventories?.length > 0) {
|
|
32
|
+
const sellercraftInvs: any[] = await Promise.all(
|
|
33
|
+
inventories.map(async (inventory: Inventory) => {
|
|
34
|
+
const inventoryPackingType: string = inventory.packingType
|
|
35
|
+
|
|
36
|
+
let packingSize: number = 1
|
|
37
|
+
if (inventoryPackingType !== defaultProductDetail.packingType) {
|
|
38
|
+
const unmatchingProductDetail: ProductDetail = product.productDetails.find(
|
|
39
|
+
productDetail => productDetail.packingType === inventoryPackingType
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
packingSize = await this.getChildPackingSize(productDetails, defaultProductDetail, unmatchingProductDetail)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { quantity: inventory.qty * packingSize - inventory.lockedQty * packingSize }
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
inventoryTotalQty = sellercraftInvs.reduce((total, currentValue) => {
|
|
50
|
+
total += currentValue.quantity
|
|
51
|
+
return total
|
|
52
|
+
}, 0)
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
const sellercraftInv: any[] = [
|
|
56
|
+
{
|
|
57
|
+
sku: product.sku,
|
|
58
|
+
gtin: defaultProductDetail.gtin,
|
|
59
|
+
stock: {
|
|
60
|
+
quantity: inventoryTotalQty,
|
|
61
|
+
unit_of_measure: 'EA'
|
|
62
|
+
},
|
|
63
|
+
package_weight_gm: defaultProductDetail.nettWeight < 1 ? 1 : defaultProductDetail.nettWeight,
|
|
64
|
+
package_dimensions: {
|
|
65
|
+
length_mm: defaultProductDetail.depth < 1 ? 1 : defaultProductDetail.depth,
|
|
66
|
+
width_mm: defaultProductDetail.width < 1 ? 1 : defaultProductDetail.width,
|
|
67
|
+
height_mm: defaultProductDetail.height < 1 ? 1 : defaultProductDetail.height
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
await SellercraftAPI.updateProduct(sellercraft, { accountId: sellercraft.accountId, sellercraftInv })
|
|
57
73
|
}
|
|
58
74
|
}
|