@things-factory/operato-mms 4.1.18 → 4.1.23
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.
- package/client/pages/order/logistics/request-ro-popup.js +7 -4
- package/dist-server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.js +109 -71
- package/dist-server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.js.map +1 -1
- package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js.map +1 -1
- package/package.json +43 -43
- package/server/graphql/resolvers/interface-with-hub/auto-update-all-marketplace-product-variation-quantity.ts +143 -83
- package/server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts +31 -26
- package/config.development.js +0 -88
|
@@ -451,11 +451,14 @@ class RequestROPopup extends LitElement {
|
|
|
451
451
|
let marketplaceOrderShippings = []
|
|
452
452
|
|
|
453
453
|
marketplaceOrderItems.map(item => {
|
|
454
|
-
const
|
|
454
|
+
const marketplaceOrderShippingItems = item.marketplaceOrderShippingItems
|
|
455
|
+
marketplaceOrderShippingItems.map(itm => {
|
|
456
|
+
const marketplaceOrderShipping = itm.marketplaceOrderShipping
|
|
455
457
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
458
|
+
if (marketplaceOrderShipping) {
|
|
459
|
+
marketplaceOrderShippings.push(marketplaceOrderShipping)
|
|
460
|
+
}
|
|
461
|
+
})
|
|
459
462
|
})
|
|
460
463
|
|
|
461
464
|
const uniqueMarketplaceOrderShippings = Array.from(new Set(marketplaceOrderShippings.map(a => a.id))).map(id => {
|
|
@@ -10,82 +10,120 @@ const shell_1 = require("@things-factory/shell");
|
|
|
10
10
|
const warehouse_base_1 = require("@things-factory/warehouse-base");
|
|
11
11
|
exports.autoUpdateAllMarketplaceProductVariationQuantityResolver = {
|
|
12
12
|
async autoUpdateAllMarketplaceProductVariationQuantity(_, { companyDomainId, warehouseId }, context) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
const companyDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne(companyDomainId);
|
|
14
|
+
const marketplaceStores = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceStore).find({
|
|
15
|
+
where: { domain: companyDomain, status: 'ACTIVE' },
|
|
16
|
+
relations: ['marketplaceDistributors']
|
|
17
|
+
});
|
|
18
|
+
const fulfilmentCenter = await integration_fulfillment_1.FulfillmentAPI.getFulfillmentCenter(warehouseId);
|
|
19
|
+
const centerId = fulfilmentCenter.centerId;
|
|
20
|
+
const warehouseDomain = await (0, typeorm_1.getRepository)(shell_1.Domain).findOne({ where: { subdomain: centerId } });
|
|
21
|
+
let products = await (0, typeorm_1.getRepository)(product_base_1.Product).find({
|
|
22
|
+
where: { domain: companyDomain },
|
|
23
|
+
relations: ['productDetails']
|
|
24
|
+
});
|
|
25
|
+
let inventoryProducts = await Promise.all(products.map(async (product) => {
|
|
26
|
+
const productDetails = product.productDetails;
|
|
27
|
+
const defaultProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0];
|
|
28
|
+
let qb = await (0, typeorm_1.getRepository)(warehouse_base_1.Inventory).createQueryBuilder('inv');
|
|
29
|
+
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
30
|
+
.andWhere('"inv"."domain_id" = :domainId')
|
|
31
|
+
.andWhere('"inv"."product_id" = :productId')
|
|
32
|
+
.andWhere('"inv"."status" != :status')
|
|
33
|
+
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
34
|
+
.setParameters({
|
|
35
|
+
domainId: warehouseDomain.id,
|
|
36
|
+
productId: product.id,
|
|
37
|
+
status: warehouse_base_1.INVENTORY_STATUS.TERMINATED,
|
|
38
|
+
locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
|
|
26
39
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
40
|
+
let inventories = await qb.getMany();
|
|
41
|
+
const inventoryQty = inventories.reduce((total, currentValue) => {
|
|
42
|
+
total += currentValue.qty;
|
|
43
|
+
return total;
|
|
44
|
+
}, 0);
|
|
45
|
+
const inventoryLockedQty = inventories.reduce((total, currentValue) => {
|
|
46
|
+
total += currentValue.lockedQty;
|
|
47
|
+
return total;
|
|
48
|
+
}, 0);
|
|
49
|
+
return {
|
|
50
|
+
product,
|
|
51
|
+
sku: product.sku,
|
|
52
|
+
name: product.name,
|
|
53
|
+
packingType: defaultProductDetail.packingType,
|
|
54
|
+
packingSize: defaultProductDetail.packingSize,
|
|
55
|
+
uom: defaultProductDetail.uom,
|
|
56
|
+
qty: inventoryQty - inventoryLockedQty
|
|
57
|
+
};
|
|
58
|
+
}));
|
|
59
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
60
|
+
let bundleProductInventories = await (0, warehouse_base_1.getProductBundleInventory)(warehouseDomain, companyDomain, inventoryProducts, tx);
|
|
61
|
+
bundleProductInventories.map(bundleProductInventory => {
|
|
62
|
+
inventoryProducts.push(bundleProductInventory);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
for (let i = 0; i < marketplaceStores.length; i++) {
|
|
66
|
+
try {
|
|
67
|
+
const marketplaceStore = marketplaceStores[i];
|
|
68
|
+
const marketplaceSetting = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceSetting).findOne({
|
|
69
|
+
where: { marketplaceStore, category: 'stock_allocation' }
|
|
70
|
+
});
|
|
71
|
+
for (let j = 0; j < inventoryProducts.length; j++) {
|
|
72
|
+
await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
73
|
+
var _a;
|
|
74
|
+
const inventoryProduct = inventoryProducts[j];
|
|
75
|
+
const marketplaceProductVariations = await tx
|
|
76
|
+
.getRepository(marketplace_base_1.MarketplaceProductVariation)
|
|
77
|
+
.find({
|
|
78
|
+
where: { domain: companyDomain, sku: inventoryProduct.sku },
|
|
79
|
+
relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
80
|
+
});
|
|
81
|
+
let storeProductVariations = marketplaceProductVariations.filter(productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id);
|
|
82
|
+
let percentageValue = 100;
|
|
83
|
+
if (storeProductVariations) {
|
|
84
|
+
for (let k = 0; k < storeProductVariations.length; k++) {
|
|
85
|
+
let storeProductVariation = storeProductVariations[k];
|
|
86
|
+
if (marketplaceSetting) {
|
|
87
|
+
percentageValue = parseInt(marketplaceSetting.value);
|
|
88
|
+
}
|
|
89
|
+
let remainQty = Math.floor((inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100));
|
|
90
|
+
if (remainQty < 0)
|
|
91
|
+
remainQty = 0;
|
|
92
|
+
let productVariationLocationId = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.locationId;
|
|
93
|
+
let adjustQty = remainQty;
|
|
94
|
+
if (marketplaceStore.platform === 'shopify') {
|
|
95
|
+
let locationIds = JSON.parse(productVariationLocationId);
|
|
96
|
+
adjustQty = adjustQty - storeProductVariation.qty;
|
|
97
|
+
if ((_a = locationIds[0]) === null || _a === void 0 ? void 0 : _a.location_id)
|
|
98
|
+
productVariationLocationId = locationIds[0].location_id;
|
|
99
|
+
}
|
|
100
|
+
let validMarketplaceDistributors = [];
|
|
101
|
+
if (marketplaceStore.marketplaceDistributors) {
|
|
102
|
+
validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(distributor => distributor.status === 'ACTIVE');
|
|
103
|
+
}
|
|
104
|
+
await integration_marketplace_1.StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
|
|
105
|
+
{
|
|
106
|
+
itemId: storeProductVariation.marketplaceProduct.itemId,
|
|
107
|
+
variationId: storeProductVariation.variationId,
|
|
108
|
+
variationSku: storeProductVariation.variationSku,
|
|
109
|
+
qty: adjustQty,
|
|
110
|
+
locationId: productVariationLocationId,
|
|
111
|
+
inventoryItemId: storeProductVariation.inventoryItemId,
|
|
112
|
+
distributors: validMarketplaceDistributors
|
|
113
|
+
}
|
|
114
|
+
]);
|
|
115
|
+
storeProductVariation.qty = remainQty;
|
|
116
|
+
await tx.getRepository(marketplace_base_1.MarketplaceProductVariation).save(storeProductVariation);
|
|
81
117
|
}
|
|
82
|
-
|
|
83
|
-
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
84
120
|
}
|
|
85
121
|
}
|
|
86
|
-
|
|
122
|
+
catch (e) {
|
|
123
|
+
console.log(e);
|
|
124
|
+
}
|
|
87
125
|
}
|
|
88
|
-
|
|
126
|
+
return true;
|
|
89
127
|
}
|
|
90
128
|
};
|
|
91
129
|
//# sourceMappingURL=auto-update-all-marketplace-product-variation-quantity.js.map
|
|
@@ -1 +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,
|
|
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,qCAAsD;AAEtD,qFAAwE;AACxE,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAqE;AACrE,iDAA8C;AAC9C,mEAAsH;AAEzG,QAAA,wDAAwD,GAAG;IACtE,KAAK,CAAC,gDAAgD,CAAC,CAAM,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE,EAAE,OAAY;QAC3G,MAAM,aAAa,GAAW,MAAM,IAAA,uBAAa,EAAC,cAAM,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QAElF,MAAM,iBAAiB,GAAuB,MAAM,IAAA,uBAAa,EAAC,0CAAgB,CAAC,CAAC,IAAI,CAAC;YACvF,KAAK,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE;YAClD,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,uBAAa,EAAC,cAAM,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAA;QAEvG,IAAI,QAAQ,GAAc,MAAM,IAAA,uBAAa,EAAC,sBAAO,CAAC,CAAC,IAAI,CAAC;YAC1D,KAAK,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE;YAChC,SAAS,EAAE,CAAC,gBAAgB,C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,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;oCAC/D,SAAS,GAAG,SAAS,GAAG,qBAAqB,CAAC,GAAG,CAAA;oCACjD,IAAI,MAAA,WAAW,CAAC,CAAC,CAAC,0CAAE,WAAW;wCAAE,0BAA0B,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;iCACzF;gCAED,IAAI,4BAA4B,GAAU,EAAE,CAAA;gCAC5C,IAAI,gBAAgB,CAAC,uBAAuB,EAAE;oCAC5C,4BAA4B,GAAG,gBAAgB,CAAC,uBAAuB,CAAC,MAAM,CAC5E,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,QAAQ,CAC/C,CAAA;iCACF;gCAED,MAAM,kCAAQ,CAAC,gCAAgC,CAAC,gBAAgB,EAAE;oCAChE;wCACE,MAAM,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,MAAM;wCACvD,WAAW,EAAE,qBAAqB,CAAC,WAAW;wCAC9C,YAAY,EAAE,qBAAqB,CAAC,YAAY;wCAChD,GAAG,EAAE,SAAS;wCACd,UAAU,EAAE,0BAA0B;wCACtC,eAAe,EAAE,qBAAqB,CAAC,eAAe;wCACtD,YAAY,EAAE,4BAA4B;qCAC3C;iCACF,CAAC,CAAA;gCAEF,qBAAqB,CAAC,GAAG,GAAG,SAAS,CAAA;gCACrC,MAAM,EAAE,CAAC,aAAa,CAAC,8CAA2B,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;6BAChF;yBACF;oBACH,CAAC,CAAC,CAAA;iBACH;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;aACf;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
|
package/dist-server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"warehouse-marketplace-products.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts"],"names":[],"mappings":";;;AAGA,uDAAsF;
|
|
1
|
+
{"version":3,"file":"warehouse-marketplace-products.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/interface-with-hub/warehouse-marketplace-products.ts"],"names":[],"mappings":";;;AAGA,uDAAsF;AAGzE,QAAA,oCAAoC,GAAG;IAClD,KAAK,CAAC,4BAA4B,CAAC,CAAM,EAAE,MAAiB,EAAE,OAAY;QACxE,IAAI;YACF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;YAC7F,OAAO,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;SAC7D;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AAEM,KAAK,UAAU,2BAA2B,CAAC,MAAiB,EAAE,MAAc,EAAE,IAAU,EAAE,EAAkB;IACjH,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,cAAc,CAAC,CAAA;IAC3E,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,cAAc,CAAC,CAAA;IAEpE,MAAM,eAAe,GAAa,MAAM,IAAA,6BAAkB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACxE,MAAM,UAAU,GAAa,MAAM,IAAA,wBAAa,EAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAE9D,MAAM,CAAC,OAAO,GAAG,CAAC,GAAG,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,CA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AClC,CAAA;4BACH,CAAC,CAAC;yBACH,CAAA;oBACH,CAAC,CAAC;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;AAzND,kEAyNC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/operato-mms",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.23",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -60,50 +60,50 @@
|
|
|
60
60
|
"@operato/scene-table": "^0.1.5",
|
|
61
61
|
"@operato/scene-timer": "^0.1.5",
|
|
62
62
|
"@operato/scene-wheel-sorter": "^0.1.5",
|
|
63
|
-
"@things-factory/apptool-ui": "^4.1.
|
|
64
|
-
"@things-factory/attachment-base": "^4.1.
|
|
65
|
-
"@things-factory/auth-ui": "^4.1.
|
|
66
|
-
"@things-factory/biz-base": "^4.1.
|
|
67
|
-
"@things-factory/board-service": "^4.1.
|
|
68
|
-
"@things-factory/board-ui": "^4.1.
|
|
69
|
-
"@things-factory/code-ui": "^4.1.
|
|
70
|
-
"@things-factory/context-ui": "^4.1.
|
|
71
|
-
"@things-factory/dashboard": "^4.1.
|
|
72
|
-
"@things-factory/export-ui": "^4.1.
|
|
73
|
-
"@things-factory/export-ui-csv": "^4.1.
|
|
74
|
-
"@things-factory/export-ui-excel": "^4.1.
|
|
75
|
-
"@things-factory/geography": "^4.1.
|
|
76
|
-
"@things-factory/grist-ui": "^4.1.
|
|
77
|
-
"@things-factory/help": "^4.1.
|
|
78
|
-
"@things-factory/i18n-base": "^4.1.
|
|
79
|
-
"@things-factory/integration-fulfillment": "^4.1.
|
|
80
|
-
"@things-factory/integration-lmd": "^4.1.
|
|
81
|
-
"@things-factory/lite-menu": "^4.1.
|
|
82
|
-
"@things-factory/marketplace-base": "^4.1.
|
|
83
|
-
"@things-factory/more-ui": "^4.1.
|
|
84
|
-
"@things-factory/notification": "^4.1.
|
|
85
|
-
"@things-factory/oauth2-client": "^4.1.
|
|
86
|
-
"@things-factory/pdf": "^4.1.
|
|
87
|
-
"@things-factory/product-base": "^4.1.
|
|
88
|
-
"@things-factory/resource-ui": "^4.1.
|
|
89
|
-
"@things-factory/scene-data-transform": "^4.1.
|
|
90
|
-
"@things-factory/scene-excel": "^4.1.
|
|
91
|
-
"@things-factory/scene-firebase": "^4.1.
|
|
92
|
-
"@things-factory/scene-form": "^4.1.
|
|
93
|
-
"@things-factory/scene-google-map": "^4.1.
|
|
94
|
-
"@things-factory/scene-graphql": "^4.1.
|
|
95
|
-
"@things-factory/scene-label": "^4.1.
|
|
96
|
-
"@things-factory/scene-marker": "^4.1.
|
|
97
|
-
"@things-factory/scene-mqtt": "^4.1.
|
|
98
|
-
"@things-factory/scene-restful": "^4.1.
|
|
99
|
-
"@things-factory/scene-visualizer": "^4.1.
|
|
100
|
-
"@things-factory/setting-ui": "^4.1.
|
|
101
|
-
"@things-factory/system-ui": "^4.1.
|
|
102
|
-
"@things-factory/warehouse-base": "^4.1.
|
|
63
|
+
"@things-factory/apptool-ui": "^4.1.22",
|
|
64
|
+
"@things-factory/attachment-base": "^4.1.22",
|
|
65
|
+
"@things-factory/auth-ui": "^4.1.22",
|
|
66
|
+
"@things-factory/biz-base": "^4.1.22",
|
|
67
|
+
"@things-factory/board-service": "^4.1.22",
|
|
68
|
+
"@things-factory/board-ui": "^4.1.22",
|
|
69
|
+
"@things-factory/code-ui": "^4.1.22",
|
|
70
|
+
"@things-factory/context-ui": "^4.1.22",
|
|
71
|
+
"@things-factory/dashboard": "^4.1.22",
|
|
72
|
+
"@things-factory/export-ui": "^4.1.22",
|
|
73
|
+
"@things-factory/export-ui-csv": "^4.1.22",
|
|
74
|
+
"@things-factory/export-ui-excel": "^4.1.22",
|
|
75
|
+
"@things-factory/geography": "^4.1.22",
|
|
76
|
+
"@things-factory/grist-ui": "^4.1.22",
|
|
77
|
+
"@things-factory/help": "^4.1.22",
|
|
78
|
+
"@things-factory/i18n-base": "^4.1.22",
|
|
79
|
+
"@things-factory/integration-fulfillment": "^4.1.22",
|
|
80
|
+
"@things-factory/integration-lmd": "^4.1.22",
|
|
81
|
+
"@things-factory/lite-menu": "^4.1.22",
|
|
82
|
+
"@things-factory/marketplace-base": "^4.1.22",
|
|
83
|
+
"@things-factory/more-ui": "^4.1.22",
|
|
84
|
+
"@things-factory/notification": "^4.1.22",
|
|
85
|
+
"@things-factory/oauth2-client": "^4.1.22",
|
|
86
|
+
"@things-factory/pdf": "^4.1.19",
|
|
87
|
+
"@things-factory/product-base": "^4.1.22",
|
|
88
|
+
"@things-factory/resource-ui": "^4.1.22",
|
|
89
|
+
"@things-factory/scene-data-transform": "^4.1.19",
|
|
90
|
+
"@things-factory/scene-excel": "^4.1.19",
|
|
91
|
+
"@things-factory/scene-firebase": "^4.1.19",
|
|
92
|
+
"@things-factory/scene-form": "^4.1.19",
|
|
93
|
+
"@things-factory/scene-google-map": "^4.1.19",
|
|
94
|
+
"@things-factory/scene-graphql": "^4.1.19",
|
|
95
|
+
"@things-factory/scene-label": "^4.1.22",
|
|
96
|
+
"@things-factory/scene-marker": "^4.1.19",
|
|
97
|
+
"@things-factory/scene-mqtt": "^4.1.19",
|
|
98
|
+
"@things-factory/scene-restful": "^4.1.19",
|
|
99
|
+
"@things-factory/scene-visualizer": "^4.1.19",
|
|
100
|
+
"@things-factory/setting-ui": "^4.1.22",
|
|
101
|
+
"@things-factory/system-ui": "^4.1.22",
|
|
102
|
+
"@things-factory/warehouse-base": "^4.1.22"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
|
-
"@things-factory/builder": "^4.1.
|
|
105
|
+
"@things-factory/builder": "^4.1.19",
|
|
106
106
|
"@types/node-fetch": "^2.5.7"
|
|
107
107
|
},
|
|
108
|
-
"gitHead": "
|
|
108
|
+
"gitHead": "f13228576595836d2a4c2e5412adf412c0f82f33"
|
|
109
109
|
}
|
|
@@ -1,99 +1,159 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConnection, getRepository } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { FulfillmentAPI } from '@things-factory/integration-fulfillment'
|
|
4
|
-
import { StoreAPI } from '@things-factory/integration-marketplace'
|
|
4
|
+
import { MarketplaceSetting, MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
5
5
|
import { MarketplaceProductVariation } from '@things-factory/marketplace-base'
|
|
6
|
-
import { Product } from '@things-factory/product-base'
|
|
6
|
+
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
7
7
|
import { Domain } from '@things-factory/shell'
|
|
8
|
-
import { Inventory } from '@things-factory/warehouse-base'
|
|
8
|
+
import { getProductBundleInventory, Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
9
9
|
|
|
10
10
|
export const autoUpdateAllMarketplaceProductVariationQuantityResolver = {
|
|
11
11
|
async autoUpdateAllMarketplaceProductVariationQuantity(_: any, { companyDomainId, warehouseId }, context: any) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
const companyDomain: Domain = await getRepository(Domain).findOne(companyDomainId)
|
|
13
|
+
|
|
14
|
+
const marketplaceStores: MarketplaceStore[] = await getRepository(MarketplaceStore).find({
|
|
15
|
+
where: { domain: companyDomain, status: 'ACTIVE' },
|
|
16
|
+
relations: ['marketplaceDistributors']
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const fulfilmentCenter = await FulfillmentAPI.getFulfillmentCenter(warehouseId)
|
|
20
|
+
const centerId: string = fulfilmentCenter.centerId
|
|
21
|
+
const warehouseDomain: Domain = await getRepository(Domain).findOne({ where: { subdomain: centerId } })
|
|
22
|
+
|
|
23
|
+
let products: Product[] = await getRepository(Product).find({
|
|
24
|
+
where: { domain: companyDomain },
|
|
25
|
+
relations: ['productDetails']
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
let inventoryProducts: any[] = await Promise.all(
|
|
29
|
+
products.map(async product => {
|
|
30
|
+
const productDetails: ProductDetail[] = product.productDetails
|
|
31
|
+
const defaultProductDetail: ProductDetail = productDetails.filter(productDetail => productDetail.isDefault)[0]
|
|
32
|
+
|
|
33
|
+
let qb = await getRepository(Inventory).createQueryBuilder('inv')
|
|
34
|
+
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
35
|
+
.andWhere('"inv"."domain_id" = :domainId')
|
|
36
|
+
.andWhere('"inv"."product_id" = :productId')
|
|
37
|
+
.andWhere('"inv"."status" != :status')
|
|
38
|
+
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
39
|
+
.setParameters({
|
|
40
|
+
domainId: warehouseDomain.id,
|
|
41
|
+
productId: product.id,
|
|
42
|
+
status: INVENTORY_STATUS.TERMINATED,
|
|
43
|
+
locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
44
|
+
})
|
|
27
45
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
let inventories: Inventory[] = await qb.getMany()
|
|
47
|
+
|
|
48
|
+
const inventoryQty: number = inventories.reduce((total, currentValue) => {
|
|
49
|
+
total += currentValue.qty
|
|
50
|
+
return total
|
|
51
|
+
}, 0)
|
|
52
|
+
|
|
53
|
+
const inventoryLockedQty: number = inventories.reduce((total, currentValue) => {
|
|
54
|
+
total += currentValue.lockedQty
|
|
55
|
+
return total
|
|
56
|
+
}, 0)
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
product,
|
|
60
|
+
sku: product.sku,
|
|
61
|
+
name: product.name,
|
|
62
|
+
packingType: defaultProductDetail.packingType,
|
|
63
|
+
packingSize: defaultProductDetail.packingSize,
|
|
64
|
+
uom: defaultProductDetail.uom,
|
|
65
|
+
qty: inventoryQty - inventoryLockedQty
|
|
48
66
|
}
|
|
67
|
+
})
|
|
68
|
+
)
|
|
49
69
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
await getConnection().transaction(async tx => {
|
|
71
|
+
let bundleProductInventories: any[] = await getProductBundleInventory(
|
|
72
|
+
warehouseDomain,
|
|
73
|
+
companyDomain,
|
|
74
|
+
inventoryProducts,
|
|
75
|
+
tx
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
bundleProductInventories.map(bundleProductInventory => {
|
|
79
|
+
inventoryProducts.push(bundleProductInventory)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
for (let i = 0; i < marketplaceStores.length; i++) {
|
|
84
|
+
try {
|
|
85
|
+
const marketplaceStore: MarketplaceStore = marketplaceStores[i]
|
|
86
|
+
|
|
87
|
+
const marketplaceSetting: MarketplaceSetting = await getRepository(MarketplaceSetting).findOne({
|
|
88
|
+
where: { marketplaceStore, category: 'stock_allocation' }
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
for (let j = 0; j < inventoryProducts.length; j++) {
|
|
92
|
+
await getConnection().transaction(async tx => {
|
|
93
|
+
const inventoryProduct = inventoryProducts[j]
|
|
94
|
+
const marketplaceProductVariations: MarketplaceProductVariation[] = await tx
|
|
95
|
+
.getRepository(MarketplaceProductVariation)
|
|
96
|
+
.find({
|
|
97
|
+
where: { domain: companyDomain, sku: inventoryProduct.sku },
|
|
98
|
+
relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(
|
|
102
|
+
productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
let percentageValue: number = 100
|
|
106
|
+
if (storeProductVariations) {
|
|
107
|
+
for (let k = 0; k < storeProductVariations.length; k++) {
|
|
108
|
+
let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]
|
|
109
|
+
if (marketplaceSetting) {
|
|
110
|
+
percentageValue = parseInt(marketplaceSetting.value)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let remainQty: number = Math.floor(
|
|
114
|
+
(inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)
|
|
115
|
+
)
|
|
116
|
+
if (remainQty < 0) remainQty = 0
|
|
117
|
+
|
|
118
|
+
let productVariationLocationId = storeProductVariation?.locationId
|
|
119
|
+
let adjustQty: number = remainQty
|
|
120
|
+
|
|
121
|
+
if (marketplaceStore.platform === 'shopify') {
|
|
122
|
+
let locationIds: any[] = JSON.parse(productVariationLocationId)
|
|
123
|
+
adjustQty = adjustQty - storeProductVariation.qty
|
|
124
|
+
if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let validMarketplaceDistributors: any[] = []
|
|
128
|
+
if (marketplaceStore.marketplaceDistributors) {
|
|
129
|
+
validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
|
|
130
|
+
distributor => distributor.status === 'ACTIVE'
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
|
|
135
|
+
{
|
|
136
|
+
itemId: storeProductVariation.marketplaceProduct.itemId,
|
|
137
|
+
variationId: storeProductVariation.variationId,
|
|
138
|
+
variationSku: storeProductVariation.variationSku,
|
|
139
|
+
qty: adjustQty,
|
|
140
|
+
locationId: productVariationLocationId,
|
|
141
|
+
inventoryItemId: storeProductVariation.inventoryItemId,
|
|
142
|
+
distributors: validMarketplaceDistributors
|
|
143
|
+
}
|
|
144
|
+
])
|
|
145
|
+
|
|
146
|
+
storeProductVariation.qty = remainQty
|
|
147
|
+
await tx.getRepository(MarketplaceProductVariation).save(storeProductVariation)
|
|
90
148
|
}
|
|
91
|
-
|
|
92
|
-
}
|
|
149
|
+
}
|
|
150
|
+
})
|
|
93
151
|
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.log(e)
|
|
94
154
|
}
|
|
155
|
+
}
|
|
95
156
|
|
|
96
|
-
|
|
97
|
-
} catch (ex) {}
|
|
157
|
+
return true
|
|
98
158
|
}
|
|
99
159
|
}
|
|
@@ -2,7 +2,6 @@ import { EntityManager } from 'typeorm'
|
|
|
2
2
|
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, getCompanyBizplace, getMyBizplace } from '@things-factory/biz-base'
|
|
5
|
-
import { Product } from '@things-factory/product-base'
|
|
6
5
|
import { Domain, ListParam } from '@things-factory/shell'
|
|
7
6
|
|
|
8
7
|
export const warehouseMarketplaceProductsResolver = {
|
|
@@ -66,7 +65,8 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
66
65
|
)
|
|
67
66
|
`)
|
|
68
67
|
|
|
69
|
-
await tx.query(
|
|
68
|
+
await tx.query(
|
|
69
|
+
`
|
|
70
70
|
CREATE TEMP TABLE "temp_inventory" ON COMMIT DROP AS (
|
|
71
71
|
select "fc"."id" as "fulfillment_id", "fc"."name" as "fulfillment_name",
|
|
72
72
|
"i2"."product_id", SUM(greatest(coalesce("locked_qty",0),0) + greatest(coalesce(oi.release_qty,0),0)) as "inventory_locked_qty", sum(coalesce("qty",0)) as "inventory_qty",
|
|
@@ -108,7 +108,9 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
108
108
|
and "i2"."status" = 'STORED'
|
|
109
109
|
group by "i2"."domain_id", "fc"."id", "fc"."name", "i2"."product_id"
|
|
110
110
|
)
|
|
111
|
-
`,
|
|
111
|
+
`,
|
|
112
|
+
[domain.id]
|
|
113
|
+
)
|
|
112
114
|
|
|
113
115
|
await tx.query(`
|
|
114
116
|
CREATE TEMP TABLE "temp_json_warehouse_marketplace_products" ON COMMIT DROP AS (
|
|
@@ -127,7 +129,8 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
127
129
|
)
|
|
128
130
|
`)
|
|
129
131
|
|
|
130
|
-
await tx.query(
|
|
132
|
+
await tx.query(
|
|
133
|
+
`
|
|
131
134
|
CREATE TEMP TABLE temp_json_warehouse_inventory ON COMMIT DROP AS (
|
|
132
135
|
select "product_id", array_to_json(array_agg((row_to_json("dt")))) AS "Json_warehouseInventory" from(
|
|
133
136
|
select "domain_id", "fulfillment_id", "fulfillment_name",
|
|
@@ -152,7 +155,9 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
152
155
|
group by "domain_id","fulfillment_id","fulfillment_name","product_id"
|
|
153
156
|
) "dt" group by "dt"."product_id"
|
|
154
157
|
)
|
|
155
|
-
`,
|
|
158
|
+
`,
|
|
159
|
+
[domain.id]
|
|
160
|
+
)
|
|
156
161
|
|
|
157
162
|
await tx.query(`
|
|
158
163
|
CREATE TEMP TABLE temp_warehouse_marketplace_products ON COMMIT DROP as (
|
|
@@ -198,30 +203,30 @@ export async function warehouseMarketplaceProduct(params: ListParam, domain: Dom
|
|
|
198
203
|
description: itm.Product_description,
|
|
199
204
|
marketplaceProduct: itm.Json_marketplaceProducts
|
|
200
205
|
? itm.Json_marketplaceProducts.map(product => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
206
|
+
return {
|
|
207
|
+
marketplaceStore: { id: product.marketplace_store_id },
|
|
208
|
+
marketplaceProductVariations: product.product_variation.map(variation => {
|
|
209
|
+
return {
|
|
210
|
+
id: variation.marketplace_product_variation_id,
|
|
211
|
+
name: variation.name,
|
|
212
|
+
qty: variation.qty,
|
|
213
|
+
reserveQty: variation.reserve_qty
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
})
|
|
213
218
|
: null,
|
|
214
219
|
warehouseInventory: itm.Json_warehouseInventory
|
|
215
220
|
? itm.Json_warehouseInventory.map(inventory => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
return {
|
|
222
|
+
bizplace: { id: inventory.fulfillment_id, name: inventory.fulfillment_name },
|
|
223
|
+
product: { id: inventory.product_id },
|
|
224
|
+
qty: inventory.inventory_qty,
|
|
225
|
+
lockedQty: inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0,
|
|
226
|
+
remainQty:
|
|
227
|
+
inventory.inventory_qty - (inventory.inventory_locked_qty ? inventory.inventory_locked_qty : 0)
|
|
228
|
+
}
|
|
229
|
+
})
|
|
225
230
|
: null
|
|
226
231
|
}
|
|
227
232
|
}),
|
package/config.development.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
domainType: 'company',
|
|
3
|
-
ormconfig: {
|
|
4
|
-
name: 'default',
|
|
5
|
-
type: 'sqlite',
|
|
6
|
-
database: 'db.sqlite',
|
|
7
|
-
synchronize: false,
|
|
8
|
-
logging: true,
|
|
9
|
-
logger: 'debug'
|
|
10
|
-
// name: 'default',
|
|
11
|
-
// type: 'postgres',
|
|
12
|
-
// database: 'postgres',
|
|
13
|
-
// username: 'postgres',
|
|
14
|
-
// password: 'abcd1234',
|
|
15
|
-
// host: 'localhost',
|
|
16
|
-
// port: 15432,
|
|
17
|
-
// synchronize: true,
|
|
18
|
-
// logging: true
|
|
19
|
-
},
|
|
20
|
-
oauth2: {
|
|
21
|
-
platforms: [
|
|
22
|
-
{
|
|
23
|
-
name: 'Operato Hub',
|
|
24
|
-
apiURL: 'http://operato-m.localhost:3000/api'
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
useVirtualHostBasedDomain: false,
|
|
29
|
-
port: 5000,
|
|
30
|
-
uploads: 'uploads',
|
|
31
|
-
attachmentsPath: 'attachments',
|
|
32
|
-
SECRET: '0xD58F835B69D207A76CC5F84a70a1D0d4C79dfC95',
|
|
33
|
-
logger: {
|
|
34
|
-
file: {
|
|
35
|
-
filename: 'logs/application-%DATE%.log',
|
|
36
|
-
datePattern: 'YYYY-MM-DD-HH',
|
|
37
|
-
zippedArchive: true,
|
|
38
|
-
maxSize: '200m',
|
|
39
|
-
maxFiles: '1m',
|
|
40
|
-
level: 'info'
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
fulfillmentIntegrationOperato: {
|
|
44
|
-
host: 'operatohub.com',
|
|
45
|
-
platform: 'operato',
|
|
46
|
-
application: 'Operato MMS',
|
|
47
|
-
appKey: '480d19cbfb0655357878119559d47333',
|
|
48
|
-
appSecret: 'dc5078bc17d50a18ef6fc3188934bbbd',
|
|
49
|
-
callback: 'https://www.myoperato.com/callback-operato'
|
|
50
|
-
},
|
|
51
|
-
marketplaceIntegrationShopee: {
|
|
52
|
-
platform: 'shopee',
|
|
53
|
-
isUAT: false,
|
|
54
|
-
application: 'Operato MMS',
|
|
55
|
-
partnerId: 846025,
|
|
56
|
-
partnerKey: 'd34cfd85a603f196a0d74ebe08043280c1a27788bb36bdffd61e7e0bb1c90b64'
|
|
57
|
-
},
|
|
58
|
-
marketplaceIntegrationLazada: {
|
|
59
|
-
platform: 'lazada',
|
|
60
|
-
application: 'operato-mms',
|
|
61
|
-
appKey: '120961',
|
|
62
|
-
appSecret: 'HB3RTNEXHlVSlBr9SmWF8AjbSUT7a825',
|
|
63
|
-
callback: 'https://myoperato.com/lazada-callback'
|
|
64
|
-
},
|
|
65
|
-
notification: {
|
|
66
|
-
fcm: {
|
|
67
|
-
serviceAccount: {
|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4yLFdolhEAyj5m0WPuYYXpjzhHhZ0W3V3ItdBkrmwIvy\nWOWu26qN0ZbwxVS2qVpHuj6iHWJKHuDZZUkFtJg3BeeBSOUHSA8TvjnA0xd83xeb\n8ZJasWoFvwKBgQDFs/gQ/gIdcq0exLfluh5nw0qgcmyHpNWJHdjqITS9IX/nqFkU\n0IYLtmdStf2jQiLmbkydHcvz9wZVvLqml67VBHhwLcwpgPULoskd34/4V0Dvzy4c\nv1Esw8H5zVqIDLeLu+VpFjZMzQrjyl6RIWbyTExEc84rVWfpQYAu3qIGOQKBgAFr\nXatEk7TdAtRNSPflTfu/rTAaSeKROjQBkvBiU8x4US1YpOBDBxUUyAtG8wKh5FHC\nfnsaGq+fM3KXJVv2R6J62mXQOfg4xyDLpWlwcBK4aSBBMoiBcsjouqSlZQlqMpdf\nZBgixqHe6U8BsFJg/6ZxC0y+e3AIss4Bo4/lb+1lAoGAFOexvaBh21K6W3inmRW4\nLlkVYJaBJ20OwokXg5aXjBiHxqmk7VLAuFbkpb5LOKH2xPILRQ0OEkn51yVymS3T\n9lLpHOFTQXt5tF2/F7NW7kaQJNlLr/h5jPi3O9XHeFmuaN2z150ZB6zzgjeGKzr8\ni+1fgTsRfDtNw8xkSH9qL1Y=\n-----END PRIVATE KEY-----\n',
|
|
71
|
-
client_email: 'firebase-adminsdk-xmm2e@operato.iam.gserviceaccount.com'
|
|
72
|
-
},
|
|
73
|
-
appConfig: {
|
|
74
|
-
apiKey: 'AIzaSyDdTM2BTLHSt2LNS0G5QB8G0i4KBXFiG7U',
|
|
75
|
-
projectId: 'operato',
|
|
76
|
-
messagingSenderId: 79537064975,
|
|
77
|
-
appId: '1:79537064975:web:32f53119e9c8c6ee2a277a'
|
|
78
|
-
},
|
|
79
|
-
serverKey:
|
|
80
|
-
'AAAAEoTHTA8:APA91bGwt-4HT82Dfwf_VwbQaKT0_qHd0Y3tuW41udjWz5Lz0Ko0mEMD6WbHHSILvQpa6yuoGGKCMsrU7VW2qWRrUm3CYpyG9oSwshNm1tIhljAnOuUfwHCoawbVLwf9qlWpHt4dwCoc'
|
|
81
|
-
},
|
|
82
|
-
vapidKey: {
|
|
83
|
-
subject: 'mailto:heartyoh@hatiolab.com',
|
|
84
|
-
publicKey: 'BAkVkITsCXBIsYL1yeaBmx5_dn57we-ZXMjirPPHzC2dan82cdEnAio_53PQ-1_w3ykWCBPrrFAWQ_d9N4cFF0o',
|
|
85
|
-
privateKey: '4pmlt3Wk019u7nqU3Q_oGZE6LbUDjjf8DpmAcn9-iss'
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|