@things-factory/marketplace-base 4.3.52 → 4.3.59
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/dist-server/graphql/resolvers/marketplace-order/auto-initialise-logistics-by-batch.js +6 -0
- package/dist-server/graphql/resolvers/marketplace-order/auto-initialise-logistics-by-batch.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/get-logistics-param.js +11 -2
- package/dist-server/graphql/resolvers/marketplace-order/get-logistics-param.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/get-order-document.js +15 -1
- package/dist-server/graphql/resolvers/marketplace-order/get-order-document.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/index.js +3 -1
- package/dist-server/graphql/resolvers/marketplace-order/index.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/initialise-logistics.js +6 -0
- package/dist-server/graphql/resolvers/marketplace-order/initialise-logistics.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/initialise-shopee-logistics-by-batch.js +28 -1
- package/dist-server/graphql/resolvers/marketplace-order/initialise-shopee-logistics-by-batch.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js +31 -25
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-orders-by-platform.js +18 -0
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-orders-by-platform.js.map +1 -0
- package/dist-server/graphql/resolvers/marketplace-order/sync-shopee-awb.js +49 -0
- package/dist-server/graphql/resolvers/marketplace-order/sync-shopee-awb.js.map +1 -0
- package/dist-server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.js +18 -11
- package/dist-server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order/index.js +2 -0
- package/dist-server/graphql/types/marketplace-order/index.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order/order-document.js +1 -0
- package/dist-server/graphql/types/marketplace-order/order-document.js.map +1 -1
- package/package.json +5 -5
- package/server/graphql/resolvers/marketplace-order/auto-initialise-logistics-by-batch.ts +7 -0
- package/server/graphql/resolvers/marketplace-order/get-logistics-param.ts +11 -2
- package/server/graphql/resolvers/marketplace-order/get-order-document.ts +17 -2
- package/server/graphql/resolvers/marketplace-order/index.ts +5 -1
- package/server/graphql/resolvers/marketplace-order/initialise-logistics.ts +8 -1
- package/server/graphql/resolvers/marketplace-order/initialise-shopee-logistics-by-batch.ts +36 -2
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +39 -33
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-orders-by-platform.ts +23 -0
- package/server/graphql/resolvers/marketplace-order/sync-shopee-awb.ts +46 -0
- package/server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.ts +23 -14
- package/server/graphql/types/marketplace-order/index.ts +2 -0
- package/server/graphql/types/marketplace-order/order-document.ts +1 -0
package/dist-server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.js
CHANGED
|
@@ -6,7 +6,7 @@ const shell_1 = require("@things-factory/shell");
|
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
|
7
7
|
const entities_1 = require("../../../entities");
|
|
8
8
|
const debug = require('debug')('things-factory:marketplace-base:sync-all-marketplace-store-product');
|
|
9
|
-
async function syncAllMarketplaceStoreProducts({
|
|
9
|
+
async function syncAllMarketplaceStoreProducts({ user, tag, marketplaceStores }) {
|
|
10
10
|
try {
|
|
11
11
|
for (var i = 0; i < (marketplaceStores === null || marketplaceStores === void 0 ? void 0 : marketplaceStores.length); i++) {
|
|
12
12
|
const marketplaceStore = marketplaceStores[i];
|
|
@@ -27,7 +27,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
27
27
|
// search for existing product
|
|
28
28
|
const existingMarketplaceProducts = await (0, typeorm_1.getRepository)(entities_1.MarketplaceProduct).find({
|
|
29
29
|
where: {
|
|
30
|
-
domain,
|
|
30
|
+
domain: marketplaceStore.domain,
|
|
31
31
|
marketplaceStore,
|
|
32
32
|
itemId: (0, typeorm_1.In)(marketplaceProducts.map(product => product.itemId.toString()))
|
|
33
33
|
},
|
|
@@ -76,7 +76,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
76
76
|
processedData++;
|
|
77
77
|
debug('processed data', processedData);
|
|
78
78
|
(0, shell_1.publishProgress)({
|
|
79
|
-
domain,
|
|
79
|
+
domain: marketplaceStore.domain,
|
|
80
80
|
tag,
|
|
81
81
|
progress: Math.floor((processedData / total) * 100),
|
|
82
82
|
message: `${processedData} / ${total}`
|
|
@@ -91,23 +91,23 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
91
91
|
// prep marketplace product data for saving
|
|
92
92
|
let marketplaceProduct = new entities_1.MarketplaceProduct(product);
|
|
93
93
|
marketplaceProduct.marketplaceStore = marketplaceStore;
|
|
94
|
-
marketplaceProduct.domain = domain;
|
|
94
|
+
marketplaceProduct.domain = marketplaceStore.domain;
|
|
95
95
|
marketplaceProduct.creator = user;
|
|
96
96
|
marketplaceProduct.updater = user;
|
|
97
97
|
await tx.getRepository(entities_1.MarketplaceProduct).save(marketplaceProduct);
|
|
98
98
|
marketplaceProductVariations = product.variations.map(variation => {
|
|
99
|
-
return Object.assign(Object.assign({}, variation), { status: 'ACTIVE', marketplaceProduct, domain: domain, creator: user, updater: user });
|
|
99
|
+
return Object.assign(Object.assign({}, variation), { status: 'ACTIVE', marketplaceProduct, domain: marketplaceStore.domain, creator: user, updater: user });
|
|
100
100
|
});
|
|
101
101
|
await tx.getRepository(entities_1.MarketplaceProductVariation).save(marketplaceProductVariations);
|
|
102
102
|
// pre-load all existing marketplace product attributes status = 'ACTIVE'
|
|
103
103
|
marketplaceProductAttributes = product.attributes.map(attribute => {
|
|
104
|
-
return Object.assign(Object.assign({}, attribute), { status: 'ACTIVE', marketplaceProduct, domain: domain, creator: user, updater: user });
|
|
104
|
+
return Object.assign(Object.assign({}, attribute), { status: 'ACTIVE', marketplaceProduct, domain: marketplaceStore.domain, creator: user, updater: user });
|
|
105
105
|
});
|
|
106
106
|
await tx.getRepository(entities_1.MarketplaceProductAttribute).save(marketplaceProductAttributes);
|
|
107
107
|
processedData++;
|
|
108
108
|
debug('processed data', processedData);
|
|
109
109
|
(0, shell_1.publishProgress)({
|
|
110
|
-
domain,
|
|
110
|
+
domain: marketplaceStore.domain,
|
|
111
111
|
tag,
|
|
112
112
|
progress: Math.floor((processedData / total) * 100),
|
|
113
113
|
message: `${processedData} / ${total}`
|
|
@@ -121,7 +121,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
121
121
|
}
|
|
122
122
|
catch (ex) {
|
|
123
123
|
(0, shell_1.publishProgress)({
|
|
124
|
-
domain,
|
|
124
|
+
domain: marketplaceStores[i].domain,
|
|
125
125
|
tag,
|
|
126
126
|
progress: -1,
|
|
127
127
|
message: 'failed'
|
|
@@ -131,12 +131,19 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
131
131
|
}
|
|
132
132
|
exports.syncAllMarketplaceStoreProductsResolver = {
|
|
133
133
|
async syncAllMarketplaceStoreProducts(_, params, context) {
|
|
134
|
-
|
|
135
|
-
const marketplaceStores = await integration_marketplace_1.StoreAPI.getMarketplaceStores(domain);
|
|
134
|
+
let marketplaceStores;
|
|
136
135
|
const tag = `progress-sync-all-product`;
|
|
136
|
+
if (context) {
|
|
137
|
+
var { domain, user } = context.state;
|
|
138
|
+
marketplaceStores = await integration_marketplace_1.StoreAPI.getMarketplaceStores(domain);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
marketplaceStores = await (0, typeorm_1.getRepository)(integration_marketplace_1.MarketplaceStore).find({
|
|
142
|
+
where: { status: 'ACTIVE' }
|
|
143
|
+
});
|
|
144
|
+
}
|
|
137
145
|
// don't make following line synchronous (await)
|
|
138
146
|
syncAllMarketplaceStoreProducts({
|
|
139
|
-
domain,
|
|
140
147
|
user,
|
|
141
148
|
tag,
|
|
142
149
|
marketplaceStores
|
package/dist-server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-all-marketplace-store-products.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.ts"],"names":[],"mappings":";;;AACA,qFAAoF;AACpF,iDAA0E;AAC1E,qCAA0D;AAC1D,gDAAgH;AAEhH,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oEAAoE,CAAC,CAAA;AAEpG,KAAK,UAAU,+BAA+B,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"sync-all-marketplace-store-products.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/marketplace-product/sync-all-marketplace-store-products.ts"],"names":[],"mappings":";;;AACA,qFAAoF;AACpF,iDAA0E;AAC1E,qCAA0D;AAC1D,gDAAgH;AAEhH,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oEAAoE,CAAC,CAAA;AAEpG,KAAK,UAAU,+BAA+B,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,iBAAiB,EAAE;IAC7E,IAAI;QACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAG,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,MAAM,CAAA,EAAE,CAAC,EAAE,EAAE;YAClD,MAAM,gBAAgB,GAAqB,iBAAiB,CAAC,CAAC,CAAC,CAAA;YAE/D,IAAI,UAAU,GAAW,CAAC,CAAA;YAC1B,IAAI,aAAa,GAAW,CAAC,CAAA;YAC7B,IAAI,QAAgB,CAAA;YACpB,IAAI,KAAK,GAAW,EAAE,CAAA;YAEtB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,UAAU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M,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;YACpC,iBAAiB,GAAG,MAAM,kCAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAA;SAChE;aAAM;YACL,iBAAiB,GAAG,MAAM,IAAA,uBAAa,EAAC,0CAAgB,CAAC,CAAC,IAAI,CAAC;gBAC7D,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;aAC5B,CAAC,CAAA;SACH;QAED,gDAAgD;QAChD,+BAA+B,CAAC;YAC9B,IAAI;YACJ,GAAG;YACH,iBAAiB;SAClB,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA"}
|
|
@@ -60,6 +60,8 @@ exports.MarketplaceOrderResolver = (0, graphql_tag_1.default) `
|
|
|
60
60
|
deleteMarketplaceOrders(names: [String]!): Boolean
|
|
61
61
|
splitOrdersByBatch(patches: [LogisticsInfo]): Boolean @transaction
|
|
62
62
|
updateMarketplaceOrder(orderNo: String!, patch: MarketplaceOrderPatch!): MarketplaceOrder @transaction
|
|
63
|
+
syncShopeeAwb: Boolean @transaction
|
|
64
|
+
syncMarketplaceOrdersByPlatform(fromCreatedDate: String, toCreatedDate: String): Boolean
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
extend type Query {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-order/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA6B;AAE7B,mDAAgC;AAChC,oDAAiC;AACjC,0DAAuC;AACvC,0DAAuC;AACvC,sDAAmC;AACnC,4DAAyC;AACzC,2DAAwC;AACxC,6DAA0C;AAC1C,kDAA+B;AAC/B,0DAAuC;AACvC,qDAAkC;AAClC,mDAAgC;AAChC,mDAAgC;AAChC,mDAAgC;AAChC,8CAA2B;AAEd,QAAA,wBAAwB,GAAG,IAAA,qBAAG,EAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-order/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA6B;AAE7B,mDAAgC;AAChC,oDAAiC;AACjC,0DAAuC;AACvC,0DAAuC;AACvC,sDAAmC;AACnC,4DAAyC;AACzC,2DAAwC;AACxC,6DAA0C;AAC1C,kDAA+B;AAC/B,0DAAuC;AACvC,qDAAkC;AAClC,mDAAgC;AAChC,mDAAgC;AAChC,mDAAgC;AAChC,8CAA2B;AAEd,QAAA,wBAAwB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkD1C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-document.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-order/order-document.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,aAAa,GAAG,IAAA,qBAAG,EAAA
|
|
1
|
+
{"version":3,"file":"order-document.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-order/order-document.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,aAAa,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;CAU/B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/marketplace-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.59",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/integration-fulfillment": "^4.3.
|
|
28
|
-
"@things-factory/integration-marketplace": "^4.3.
|
|
29
|
-
"@things-factory/product-base": "^4.3.
|
|
27
|
+
"@things-factory/integration-fulfillment": "^4.3.59",
|
|
28
|
+
"@things-factory/integration-marketplace": "^4.3.59",
|
|
29
|
+
"@things-factory/product-base": "^4.3.59",
|
|
30
30
|
"@things-factory/shell": "^4.3.47"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "923ea2407895243b6e4030e75580aaa87b17e9dc"
|
|
33
33
|
}
|
|
@@ -8,6 +8,10 @@ import { MARKETPLACE_PLATFORM, ORDER_STATUS } from '../../../constants'
|
|
|
8
8
|
import { MarketplaceOrder, MarketplaceOrderItem } from '../../../entities'
|
|
9
9
|
import { getLogisticsParam } from '../marketplace-order/get-logistics-param'
|
|
10
10
|
|
|
11
|
+
import { config } from '@things-factory/env'
|
|
12
|
+
const shopeeConfig = config.get('marketplaceIntegrationShopee', {})
|
|
13
|
+
const { v2 } = shopeeConfig
|
|
14
|
+
|
|
11
15
|
export const autoInitialiseLogisticsByBatch = {
|
|
12
16
|
async autoInitialiseLogisticsByBatch(_: any, { companyDomainId }, context: any) {
|
|
13
17
|
const { user }: { user: User } = context.state
|
|
@@ -102,6 +106,9 @@ export const autoInitialiseLogisticsByBatch = {
|
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
await StoreAPI.initLogistics(marketplaceStore, { deliveryType, orderNo: marketplaceOrder.orderNo })
|
|
109
|
+
if (marketplaceStore.platform == MARKETPLACE_PLATFORM.SHOPEE && v2) {
|
|
110
|
+
await StoreAPI.createShippingDocument(marketplaceStore, { orderNo: marketplaceOrder.orderNo })
|
|
111
|
+
}
|
|
105
112
|
} else if (marketplaceStore.platform == MARKETPLACE_PLATFORM.LAZADA) {
|
|
106
113
|
const shippingProviders: any[] = await StoreAPI.getStoreLogistics(marketplaceStore, {})
|
|
107
114
|
const shippingProvider: string = shippingProviders[0].name
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { config } from '@things-factory/env'
|
|
2
|
+
const shopeeConfig = config.get('marketplaceIntegrationShopee', {})
|
|
3
|
+
const { v2 } = shopeeConfig
|
|
4
|
+
|
|
1
5
|
import { StoreAPI } from '@things-factory/integration-marketplace'
|
|
2
6
|
|
|
3
7
|
export const getLogisticsParam = {
|
|
@@ -10,8 +14,13 @@ export const getLogisticsParam = {
|
|
|
10
14
|
logisticsParam.logisticsDetail.pickup = await Promise.all(
|
|
11
15
|
logisticsParam.logisticsDetail.pickup.map(async address => {
|
|
12
16
|
delete address.addressFlag
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
let timeSlot
|
|
18
|
+
if (v2) {
|
|
19
|
+
timeSlot = address.timeSlot
|
|
20
|
+
} else {
|
|
21
|
+
const addressId = address.addressId
|
|
22
|
+
timeSlot = await StoreAPI.getTimeSlot(store, { orderNo, addressId })
|
|
23
|
+
}
|
|
15
24
|
if (timeSlot?.length) {
|
|
16
25
|
return {
|
|
17
26
|
...address,
|
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
} from '../../../entities'
|
|
11
11
|
import { getETraxOrderDocumentFunction } from '../marketplace-order'
|
|
12
12
|
|
|
13
|
+
import { config } from '@things-factory/env'
|
|
14
|
+
const shopeeConfig = config.get('marketplaceIntegrationShopee', {})
|
|
15
|
+
const { v2 } = shopeeConfig
|
|
16
|
+
|
|
13
17
|
export const getOrderDocumentResolver = {
|
|
14
18
|
async getOrderDocument(_: any, { orderNo, docType }, context: any) {
|
|
15
19
|
const { tx }: { tx: EntityManager } = context.state
|
|
@@ -86,8 +90,6 @@ export const getOrderDocumentResolver = {
|
|
|
86
90
|
const storeId = foundMarketplaceOrders.map((order: MarketplaceOrder) => order.marketplaceStore.id)
|
|
87
91
|
const marketplaceStore: MarketplaceStore = await StoreAPI.getMarketplaceStore(storeId[0])
|
|
88
92
|
|
|
89
|
-
orderDocument = await StoreAPI.getStoreOrderDocument(marketplaceStore, { docRefNo, docType })
|
|
90
|
-
|
|
91
93
|
let marketplaceOrderShippings: MarketplaceOrderShipping[] = []
|
|
92
94
|
marketplaceOrderItems.map((item, idx) => {
|
|
93
95
|
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] = item[idx].marketplaceOrderShippingItems
|
|
@@ -106,6 +108,17 @@ export const getOrderDocumentResolver = {
|
|
|
106
108
|
return marketplaceOrderShippings.find(a => a.id === id)
|
|
107
109
|
})
|
|
108
110
|
|
|
111
|
+
if (marketplaceStore.platform == 'shopee' && v2) {
|
|
112
|
+
orderDocument = [
|
|
113
|
+
{
|
|
114
|
+
orderNo: uniqueMarketplaceOrderShippings[0].orderNoRef,
|
|
115
|
+
airwayBill: uniqueMarketplaceOrderShippings[0].airwayBill
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
} else {
|
|
119
|
+
orderDocument = await StoreAPI.getStoreOrderDocument(marketplaceStore, { docRefNo, docType })
|
|
120
|
+
}
|
|
121
|
+
|
|
109
122
|
if (docType === 'invoice') {
|
|
110
123
|
uniqueMarketplaceOrderShippings = uniqueMarketplaceOrderShippings.map(
|
|
111
124
|
(marketplaceOrderShipping: MarketplaceOrderShipping) => {
|
|
@@ -129,6 +142,8 @@ export const getOrderDocumentResolver = {
|
|
|
129
142
|
tx.getRepository(MarketplaceOrderShipping).save(uniqueMarketplaceOrderShippings)
|
|
130
143
|
}
|
|
131
144
|
|
|
145
|
+
orderDocument[0].isShopeeV2 = v2
|
|
146
|
+
|
|
132
147
|
return orderDocument
|
|
133
148
|
}
|
|
134
149
|
}
|
|
@@ -29,6 +29,8 @@ import { syncAllMarketplaceOrder } from './sync-all-marketplace-order'
|
|
|
29
29
|
import { syncMarketplaceOrder } from './sync-marketplace-order'
|
|
30
30
|
import { updateMarketplaceOrder } from './update-marketplace-order'
|
|
31
31
|
import { updateOrderReadyToShip } from './update-order-ready-to-ship'
|
|
32
|
+
import { syncShopeeAwb } from './sync-shopee-awb'
|
|
33
|
+
import { syncMarketplaceOrdersByPlatform } from './sync-marketplace-orders-by-platform'
|
|
32
34
|
|
|
33
35
|
export const MarketplaceOrderResolver = {
|
|
34
36
|
Query: {
|
|
@@ -64,7 +66,9 @@ export const MarketplaceOrderResolver = {
|
|
|
64
66
|
...updateMarketplaceOrder,
|
|
65
67
|
...setOwnShippingProviderByOrdersResolver,
|
|
66
68
|
...autoInitialiseLogisticsByBatch,
|
|
67
|
-
...autoUpdateOrderReadyToShip
|
|
69
|
+
...autoUpdateOrderReadyToShip,
|
|
70
|
+
...syncShopeeAwb,
|
|
71
|
+
...syncMarketplaceOrdersByPlatform
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
|
|
@@ -2,6 +2,10 @@ import { MarketplaceStore, StoreAPI } from '@things-factory/integration-marketpl
|
|
|
2
2
|
import { EntityManager } from 'typeorm'
|
|
3
3
|
import { MarketplaceOrder } from '../../../entities'
|
|
4
4
|
|
|
5
|
+
import { config } from '@things-factory/env'
|
|
6
|
+
const shopeeConfig = config.get('marketplaceIntegrationShopee', {})
|
|
7
|
+
const { v2 } = shopeeConfig
|
|
8
|
+
|
|
5
9
|
export const initialiseLogistics = {
|
|
6
10
|
async initialiseLogistics(_: any, { deliveryType, orderNo }, context: any) {
|
|
7
11
|
const { tx }: { tx: EntityManager } = context.state
|
|
@@ -15,6 +19,9 @@ export const initialiseLogistics = {
|
|
|
15
19
|
const marketplaceStore: MarketplaceStore = await StoreAPI.getMarketplaceStore(storeId)
|
|
16
20
|
|
|
17
21
|
await StoreAPI.initLogistics(marketplaceStore, { deliveryType, orderNo })
|
|
18
|
-
|
|
22
|
+
if (marketplaceStore.platform == 'shopee' && v2) {
|
|
23
|
+
await StoreAPI.createShippingDocument(marketplaceStore, { orderNo })
|
|
24
|
+
}
|
|
25
|
+
return true
|
|
19
26
|
}
|
|
20
27
|
}
|
|
@@ -2,12 +2,19 @@ import { getRepository } from 'typeorm'
|
|
|
2
2
|
|
|
3
3
|
import { MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
4
4
|
|
|
5
|
-
import { MarketplaceOrder } from '../../../entities'
|
|
5
|
+
import { MarketplaceOrder, MarketplaceOrderShipping } from '../../../entities'
|
|
6
|
+
|
|
7
|
+
import { config } from '@things-factory/env'
|
|
8
|
+
const shopeeConfig = config.get('marketplaceIntegrationShopee', {})
|
|
9
|
+
const { v2 } = shopeeConfig
|
|
6
10
|
|
|
7
11
|
export const initialiseShopeeLogisticsByBatch = {
|
|
8
12
|
async initialiseShopeeLogisticsByBatch(_: any, { patches }, context: any) {
|
|
9
13
|
await Promise.all(
|
|
10
14
|
patches.map(async patch => {
|
|
15
|
+
if (patch?.ownTrackingNo) {
|
|
16
|
+
patch.trackingNo = patch.ownTrackingNo
|
|
17
|
+
}
|
|
11
18
|
let foundMarketplaceOrder: MarketplaceOrder = await getRepository(MarketplaceOrder).findOne({
|
|
12
19
|
where: { id: patch.id },
|
|
13
20
|
relations: ['marketplaceStore', 'marketplaceOrderItems']
|
|
@@ -16,7 +23,7 @@ export const initialiseShopeeLogisticsByBatch = {
|
|
|
16
23
|
|
|
17
24
|
const storeId = foundMarketplaceOrder.marketplaceStore.id
|
|
18
25
|
const marketplaceStore: MarketplaceStore = await StoreAPI.getMarketplaceStore(storeId)
|
|
19
|
-
|
|
26
|
+
let storeOrder = await StoreAPI.getStoreOrder(marketplaceStore, { orderNo: patch.orderNo })
|
|
20
27
|
|
|
21
28
|
if (storeOrder?.status == 'ready_to_ship' && patch.deliveryType) {
|
|
22
29
|
let deliveryType = {}
|
|
@@ -57,6 +64,33 @@ export const initialiseShopeeLogisticsByBatch = {
|
|
|
57
64
|
|
|
58
65
|
await StoreAPI.initLogistics(marketplaceStore, { deliveryType, orderNo: patch.orderNo })
|
|
59
66
|
}
|
|
67
|
+
|
|
68
|
+
storeOrder = await StoreAPI.getStoreOrder(marketplaceStore, { orderNo: patch.orderNo })
|
|
69
|
+
|
|
70
|
+
let marketplaceOrderShippings: MarketplaceOrderShipping[] = await getRepository(MarketplaceOrderShipping).find({
|
|
71
|
+
where: { orderNoRef: foundMarketplaceOrder.name }
|
|
72
|
+
})
|
|
73
|
+
for (let i = 0; i < marketplaceOrderShippings.length; i++) {
|
|
74
|
+
let marketplaceOrderShipping = marketplaceOrderShippings[i]
|
|
75
|
+
|
|
76
|
+
marketplaceOrderShipping.trackingNo = storeOrder?.trackingNo
|
|
77
|
+
marketplaceOrderShipping.transporter = patch?.shippingProvider || storeOrder?.orderShipping?.transporter
|
|
78
|
+
marketplaceOrderShipping.ownTransporter = patch?.shippingProvider || null
|
|
79
|
+
marketplaceOrderShipping.ownTrackingNo = patch.ownTrackingNo || null
|
|
80
|
+
|
|
81
|
+
await getRepository(MarketplaceOrderShipping).save(marketplaceOrderShipping)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
foundMarketplaceOrder.shippingProvider = patch?.shippingProvider || storeOrder?.orderShipping?.transporter
|
|
85
|
+
foundMarketplaceOrder.ownShippingProvider = patch?.shippingProvider || null
|
|
86
|
+
foundMarketplaceOrder.trackingNo = storeOrder?.trackingNo
|
|
87
|
+
foundMarketplaceOrder.status = storeOrder.status
|
|
88
|
+
|
|
89
|
+
await getRepository(MarketplaceOrder).save(foundMarketplaceOrder)
|
|
90
|
+
|
|
91
|
+
// if (v2) {
|
|
92
|
+
// await StoreAPI.createShippingDocument(marketplaceStore, { orderNo: patch.orderNo })
|
|
93
|
+
// }
|
|
60
94
|
})
|
|
61
95
|
)
|
|
62
96
|
return true
|
|
@@ -41,15 +41,19 @@ export const syncMarketplaceOrder = {
|
|
|
41
41
|
let lastOrderId: string
|
|
42
42
|
var limit: number = 100
|
|
43
43
|
const disallowCancelStatuses: string[] = ['CANCELLED', 'PENDING_CANCEL']
|
|
44
|
+
let nextCursor: string
|
|
44
45
|
|
|
45
46
|
while (hasMorePage) {
|
|
46
|
-
const { results: marketplaceOrders, more } = await StoreAPI.getStoreOrders(marketplaceStore, {
|
|
47
|
+
const { results: marketplaceOrders, more, cursor } = await StoreAPI.getStoreOrders(marketplaceStore, {
|
|
47
48
|
fromCreatedDate,
|
|
48
49
|
toCreatedDate,
|
|
49
50
|
pagination: { page, limit },
|
|
50
|
-
lastOrderId
|
|
51
|
+
lastOrderId,
|
|
52
|
+
nextCursor
|
|
51
53
|
})
|
|
52
54
|
|
|
55
|
+
nextCursor = cursor
|
|
56
|
+
|
|
53
57
|
if (marketplaceOrders?.length == 0) throw new Error('There is no order available to sync')
|
|
54
58
|
for (var i = 0; i < marketplaceOrders.length; i++) {
|
|
55
59
|
await getConnection().transaction(async tx => {
|
|
@@ -696,39 +700,41 @@ export const syncMarketplaceOrder = {
|
|
|
696
700
|
hasMorePage = more
|
|
697
701
|
}
|
|
698
702
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
703
|
+
try {
|
|
704
|
+
if (marketplaceStore.platform === 'shopee') {
|
|
705
|
+
let pageNo: number = 1
|
|
706
|
+
let hasMore = true
|
|
707
|
+
let perPage: number = 100
|
|
708
|
+
var payoutDateList = []
|
|
709
|
+
|
|
710
|
+
while (hasMore) {
|
|
711
|
+
const { result: payoutDates, more } = await StoreAPI.getStoreOrderPayoutDates(marketplaceStore, {
|
|
712
|
+
fromCreatedDate,
|
|
713
|
+
toCreatedDate,
|
|
714
|
+
pagination: { page: pageNo, limit: perPage }
|
|
715
|
+
})
|
|
716
|
+
|
|
717
|
+
payoutDateList.push(...payoutDates)
|
|
718
|
+
if (more) pageNo++
|
|
719
|
+
hasMore = more
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
await getConnection().transaction(async tx => {
|
|
723
|
+
await Promise.all(
|
|
724
|
+
payoutDateList.map(async item => {
|
|
725
|
+
await tx.getRepository(MarketplaceOrder).update(
|
|
726
|
+
{
|
|
727
|
+
orderNo: item.orderNo
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
payoutDate: item.payoutDate
|
|
731
|
+
}
|
|
732
|
+
)
|
|
733
|
+
})
|
|
734
|
+
)
|
|
710
735
|
})
|
|
711
|
-
|
|
712
|
-
payoutDateList.push(...payoutDates)
|
|
713
|
-
if (more) pageNo++
|
|
714
|
-
hasMore = more
|
|
715
736
|
}
|
|
716
|
-
|
|
717
|
-
await getConnection().transaction(async tx => {
|
|
718
|
-
await Promise.all(
|
|
719
|
-
payoutDateList.map(async item => {
|
|
720
|
-
await tx.getRepository(MarketplaceOrder).update(
|
|
721
|
-
{
|
|
722
|
-
orderNo: item.orderNo
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
payoutDate: item.payoutDate
|
|
726
|
-
}
|
|
727
|
-
)
|
|
728
|
-
})
|
|
729
|
-
)
|
|
730
|
-
})
|
|
731
|
-
}
|
|
737
|
+
} catch (e) {}
|
|
732
738
|
return true
|
|
733
739
|
}
|
|
734
740
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getRepository } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
4
|
+
|
|
5
|
+
import { syncMarketplaceOrder } from './sync-marketplace-order'
|
|
6
|
+
|
|
7
|
+
export const syncMarketplaceOrdersByPlatform = {
|
|
8
|
+
async syncMarketplaceOrdersByPlatform(_: any, { fromCreatedDate, toCreatedDate }, context: any) {
|
|
9
|
+
let stores: MarketplaceStore[] = await getRepository(MarketplaceStore).find({
|
|
10
|
+
where: { status: 'ACTIVE' }
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
for (let store of stores) {
|
|
14
|
+
syncMarketplaceOrder.syncMarketplaceOrder(
|
|
15
|
+
_,
|
|
16
|
+
{ storeId: store.id, fromCreatedDate, toCreatedDate, scheduler: true },
|
|
17
|
+
context
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getRepository, createQueryBuilder } from 'typeorm'
|
|
2
|
+
import { MarketplaceOrder, MarketplaceOrderShipping } from '../../../entities'
|
|
3
|
+
import { StoreAPI } from '@things-factory/integration-marketplace'
|
|
4
|
+
|
|
5
|
+
export const syncShopeeAwb = {
|
|
6
|
+
async syncShopeeAwb(_: any, {}, context: any) {
|
|
7
|
+
let marketplaceOrders: MarketplaceOrder[] = await getRepository(MarketplaceOrder)
|
|
8
|
+
.createQueryBuilder('mo')
|
|
9
|
+
.select('mo')
|
|
10
|
+
.addSelect('ms')
|
|
11
|
+
.distinctOn(['mo.name'])
|
|
12
|
+
.innerJoin('mo.marketplaceStore', 'ms')
|
|
13
|
+
.innerJoin('marketplace_order_shippings', 'mos', 'mo.name = mos.order_no_ref')
|
|
14
|
+
.where('ms.platform = :platform', { platform: 'shopee' })
|
|
15
|
+
.andWhere('ms.status = :ms_status', { ms_status: 'ACTIVE' })
|
|
16
|
+
.andWhere('ms.is_own_transport = false')
|
|
17
|
+
.andWhere('mo.status = :status', { status: 'processed' })
|
|
18
|
+
.andWhere('mos.airway_bill is null')
|
|
19
|
+
.getMany()
|
|
20
|
+
|
|
21
|
+
for (let marketplaceOrder of marketplaceOrders) {
|
|
22
|
+
let docResult
|
|
23
|
+
try {
|
|
24
|
+
docResult = await StoreAPI.getShippingDocumentResult(marketplaceOrder.marketplaceStore, {
|
|
25
|
+
orderNo: [marketplaceOrder.name]
|
|
26
|
+
})
|
|
27
|
+
} catch (e) {
|
|
28
|
+
await StoreAPI.createShippingDocument(marketplaceOrder.marketplaceStore, {
|
|
29
|
+
orderNo: marketplaceOrder.name
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
if (docResult) {
|
|
33
|
+
let downloadResult = await StoreAPI.getStoreOrderDocument(marketplaceOrder.marketplaceStore, {
|
|
34
|
+
docRefNo: [marketplaceOrder.name],
|
|
35
|
+
docType: 'shippingLabel'
|
|
36
|
+
})
|
|
37
|
+
await createQueryBuilder()
|
|
38
|
+
.update(MarketplaceOrderShipping)
|
|
39
|
+
.set({ airwayBill: downloadResult[0].airwayBill })
|
|
40
|
+
.where('order_no_ref = :order_no_ref', { order_no_ref: marketplaceOrder.name })
|
|
41
|
+
.execute()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -6,10 +6,10 @@ import { MarketplaceProduct, MarketplaceProductAttribute, MarketplaceProductVari
|
|
|
6
6
|
|
|
7
7
|
const debug = require('debug')('things-factory:marketplace-base:sync-all-marketplace-store-product')
|
|
8
8
|
|
|
9
|
-
async function syncAllMarketplaceStoreProducts({
|
|
9
|
+
async function syncAllMarketplaceStoreProducts({ user, tag, marketplaceStores }) {
|
|
10
10
|
try {
|
|
11
11
|
for (var i = 0; i < marketplaceStores?.length; i++) {
|
|
12
|
-
const marketplaceStore = marketplaceStores[i]
|
|
12
|
+
const marketplaceStore: MarketplaceStore = marketplaceStores[i]
|
|
13
13
|
|
|
14
14
|
let totalPages: number = 1
|
|
15
15
|
let processedData: number = 0
|
|
@@ -17,7 +17,11 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
17
17
|
var limit: number = 50
|
|
18
18
|
|
|
19
19
|
for (let page = 0; page < totalPages; page++) {
|
|
20
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
results: marketplaceProducts,
|
|
22
|
+
total,
|
|
23
|
+
page_info
|
|
24
|
+
} = await StoreAPI.getStoreProducts(marketplaceStore, {
|
|
21
25
|
pagination: { page, limit },
|
|
22
26
|
pageInfo
|
|
23
27
|
})
|
|
@@ -30,7 +34,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
30
34
|
// search for existing product
|
|
31
35
|
const existingMarketplaceProducts: MarketplaceProduct[] = await getRepository(MarketplaceProduct).find({
|
|
32
36
|
where: {
|
|
33
|
-
domain,
|
|
37
|
+
domain: marketplaceStore.domain,
|
|
34
38
|
marketplaceStore,
|
|
35
39
|
itemId: In(marketplaceProducts.map(product => product.itemId.toString()))
|
|
36
40
|
},
|
|
@@ -121,7 +125,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
121
125
|
debug('processed data', processedData)
|
|
122
126
|
|
|
123
127
|
publishProgress({
|
|
124
|
-
domain,
|
|
128
|
+
domain: marketplaceStore.domain,
|
|
125
129
|
tag,
|
|
126
130
|
progress: Math.floor((processedData / total) * 100),
|
|
127
131
|
message: `${processedData} / ${total}`
|
|
@@ -138,7 +142,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
138
142
|
// prep marketplace product data for saving
|
|
139
143
|
let marketplaceProduct: MarketplaceProduct = new MarketplaceProduct(product)
|
|
140
144
|
marketplaceProduct.marketplaceStore = marketplaceStore
|
|
141
|
-
marketplaceProduct.domain = domain
|
|
145
|
+
marketplaceProduct.domain = marketplaceStore.domain
|
|
142
146
|
marketplaceProduct.creator = user
|
|
143
147
|
marketplaceProduct.updater = user
|
|
144
148
|
await tx.getRepository(MarketplaceProduct).save(marketplaceProduct)
|
|
@@ -148,7 +152,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
148
152
|
...variation,
|
|
149
153
|
status: 'ACTIVE',
|
|
150
154
|
marketplaceProduct,
|
|
151
|
-
domain: domain,
|
|
155
|
+
domain: marketplaceStore.domain,
|
|
152
156
|
creator: user,
|
|
153
157
|
updater: user
|
|
154
158
|
}
|
|
@@ -161,7 +165,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
161
165
|
...attribute,
|
|
162
166
|
status: 'ACTIVE',
|
|
163
167
|
marketplaceProduct,
|
|
164
|
-
domain: domain,
|
|
168
|
+
domain: marketplaceStore.domain,
|
|
165
169
|
creator: user,
|
|
166
170
|
updater: user
|
|
167
171
|
}
|
|
@@ -172,7 +176,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
172
176
|
debug('processed data', processedData)
|
|
173
177
|
|
|
174
178
|
publishProgress({
|
|
175
|
-
domain,
|
|
179
|
+
domain: marketplaceStore.domain,
|
|
176
180
|
tag,
|
|
177
181
|
progress: Math.floor((processedData / total) * 100),
|
|
178
182
|
message: `${processedData} / ${total}`
|
|
@@ -185,7 +189,7 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
185
189
|
return true
|
|
186
190
|
} catch (ex) {
|
|
187
191
|
publishProgress({
|
|
188
|
-
domain,
|
|
192
|
+
domain: marketplaceStores[i].domain,
|
|
189
193
|
tag,
|
|
190
194
|
progress: -1,
|
|
191
195
|
message: 'failed'
|
|
@@ -197,14 +201,19 @@ async function syncAllMarketplaceStoreProducts({ domain, user, tag, marketplaceS
|
|
|
197
201
|
|
|
198
202
|
export const syncAllMarketplaceStoreProductsResolver = {
|
|
199
203
|
async syncAllMarketplaceStoreProducts(_: any, params: ListParam, context: any) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const marketplaceStores: MarketplaceStore[] = await StoreAPI.getMarketplaceStores(domain)
|
|
204
|
+
let marketplaceStores: MarketplaceStore[]
|
|
203
205
|
const tag = `progress-sync-all-product`
|
|
206
|
+
if (context) {
|
|
207
|
+
var { domain, user } = context.state
|
|
208
|
+
marketplaceStores = await StoreAPI.getMarketplaceStores(domain)
|
|
209
|
+
} else {
|
|
210
|
+
marketplaceStores = await getRepository(MarketplaceStore).find({
|
|
211
|
+
where: { status: 'ACTIVE' }
|
|
212
|
+
})
|
|
213
|
+
}
|
|
204
214
|
|
|
205
215
|
// don't make following line synchronous (await)
|
|
206
216
|
syncAllMarketplaceStoreProducts({
|
|
207
|
-
domain,
|
|
208
217
|
user,
|
|
209
218
|
tag,
|
|
210
219
|
marketplaceStores
|