@things-factory/integration-sellercraft 5.0.14 → 6.0.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/dist-server/controllers/sellercraft/sellercraft.js +6 -6
  2. package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
  3. package/dist-server/controllers/sellercraft-api/decorators.js +12 -6
  4. package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-api/index.js +2 -2
  6. package/dist-server/controllers/sellercraft-api/index.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +5 -3
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration-api/index.js +2 -2
  10. package/dist-server/controllers/sellercraft-channel-integration-api/index.js.map +1 -1
  11. package/dist-server/routers/sellercraft-router.js +29 -3
  12. package/dist-server/routers/sellercraft-router.js.map +1 -1
  13. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +294 -258
  14. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  15. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +59 -16
  16. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  17. package/dist-server/service/marketplace-channel/marketplace-channel.js +8 -4
  18. package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
  19. package/dist-server/service/sellercraft/sellercraft-mutation.js +6 -4
  20. package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
  21. package/dist-server/service/sellercraft/sellercraft-query.js +6 -8
  22. package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
  23. package/dist-server/service/sellercraft/sellercraft.js +8 -4
  24. package/dist-server/service/sellercraft/sellercraft.js.map +1 -1
  25. package/dist-server/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +16 -16
  27. package/server/controllers/sellercraft/sellercraft.ts +6 -6
  28. package/server/controllers/sellercraft-api/decorators.ts +11 -6
  29. package/server/controllers/sellercraft-api/index.ts +1 -1
  30. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +5 -3
  31. package/server/controllers/sellercraft-channel-integration-api/index.ts +1 -1
  32. package/server/routers/sellercraft-router.ts +45 -4
  33. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +348 -310
  34. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +78 -17
  35. package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
  36. package/server/service/sellercraft/sellercraft-mutation.ts +17 -9
  37. package/server/service/sellercraft/sellercraft-query.ts +7 -8
  38. package/server/service/sellercraft/sellercraft.ts +5 -1
@@ -3,22 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MarketplaceChannelOrderMutation = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const type_graphql_1 = require("type-graphql");
6
- const typeorm_1 = require("typeorm");
7
- const env_1 = require("@things-factory/env");
8
6
  const integration_marketplace_1 = require("@things-factory/integration-marketplace");
7
+ const shell_1 = require("@things-factory/shell");
9
8
  const constants_1 = require("../../constants");
10
9
  const sellercraft_channel_integration_api_1 = require("../../controllers/sellercraft-channel-integration-api");
11
- const marketplace_channel_1 = require("./marketplace-channel");
12
10
  const tokencraft_util_1 = require("../../utils/tokencraft-util");
11
+ const marketplace_channel_1 = require("./marketplace-channel");
13
12
  let MarketplaceChannelOrderMutation = class MarketplaceChannelOrderMutation {
14
- async syncAllMarketplaceChannelOrders(context, fromCreatedDate, toCreatedDate, fromUpdatedDate, toUpdatedDate) {
13
+ async syncAllMarketplaceChannelOrders(context, fromCreatedDate, toCreatedDate, fromUpdatedDate, toUpdatedDate, channelId, shopId, airflow) {
15
14
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
16
- const sellercraftChannelIntegrationConfig = env_1.config.get('sellercraftChannelIntegrationConfig', {});
17
- const channels = await (0, typeorm_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find({ where: { isActive: true } });
15
+ let channels = await (0, shell_1.getRepository)(marketplace_channel_1.MarketplaceChannel).find({ where: { isActive: true } });
16
+ let errors = [];
17
+ if (channelId) {
18
+ channels = channels.filter(channel => channel.channelId == channelId);
19
+ }
18
20
  for (var i = 0; i < channels.length; i++) {
19
21
  try {
20
22
  const channel = channels[i];
21
23
  let shops = await (0, tokencraft_util_1.getShops)(channel.channelId);
24
+ if (shopId) {
25
+ shops = shops.filter(shop => shop.channel_shop_id == shopId);
26
+ }
22
27
  for (var j = 0; j < shops.length; j++) {
23
28
  try {
24
29
  var store = {
@@ -39,7 +44,7 @@ let MarketplaceChannelOrderMutation = class MarketplaceChannelOrderMutation {
39
44
  let hasMorePage = true;
40
45
  let lastOrderId;
41
46
  let cursor;
42
- var limit = 50;
47
+ var limit = 20;
43
48
  while (hasMorePage) {
44
49
  const { results: marketplaceOrders, more, nextCursor } = await integration_marketplace_1.StoreAPI.getStoreOrders(store, {
45
50
  fromCreatedDate,
@@ -50,266 +55,294 @@ let MarketplaceChannelOrderMutation = class MarketplaceChannelOrderMutation {
50
55
  lastOrderId,
51
56
  nextCursor: cursor
52
57
  });
53
- orderResult.push(...marketplaceOrders);
54
- if (more)
55
- page++;
56
- hasMorePage = more;
57
- cursor = nextCursor;
58
- }
59
- var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
60
- let mappedOrderResult = orderResult.map(order => {
61
- let id = store.platform == 'magento' || store.platform == 'shopify' ? order.name : order.orderNo;
62
- let { firstName: custFirstName, lastName: custLastName, orderCreatedAt: createdAt, orderUpdatedAt: updatedAt, status, sellercraftStatus, isSOF } = order;
63
- let { first_name: billFirstName, last_name: billLastName, address_1: billAddress1, address_2: billAddress2, address_3: billAddress3, address_4: billAddress4, address_5: billAddress5, city: billCity, postcode: billPostalCode, country: billCountry, phone: billPhone1, phone_2: billPhone2 } = order === null || order === void 0 ? void 0 : order.billing;
64
- let { first_name: shipFirstName, last_name: shipLastName, address_1: shipAddress1, address_2: shipAddress2, address_3: shipAddress3, address_4: shipAddress4, address_5: shipAddress5, city: shipCity, postcode: shipPostalCode, country: shipCountry, phone: shipPhone1, phone_2: shipPhone2 } = order.shipping;
65
- let orderPackage = (order === null || order === void 0 ? void 0 : order.orderPackage) || {};
66
- let orderItems = order.orderItems.map(item => {
67
- let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item;
58
+ var sellercraftStore = Object.assign(Object.assign({}, store), { platform: 'sellercraftChannelIntegration' });
59
+ let mappedOrderResult = marketplaceOrders.map(order => {
60
+ let id = store.platform == 'magento' || store.platform == 'shopify' ? order.name : order.orderNo;
61
+ let { firstName: custFirstName, lastName: custLastName, orderCreatedAt: createdAt, orderUpdatedAt: updatedAt, status, sellercraftStatus, isSOF, orderLineList, sellercraftDisplayOrderNo } = order;
62
+ let { first_name: billFirstName, last_name: billLastName, address_1: billAddress1, address_2: billAddress2, address_3: billAddress3, address_4: billAddress4, address_5: billAddress5, city: billCity, postcode: billPostalCode, country: billCountry, phone: billPhone1, phone_2: billPhone2 } = order === null || order === void 0 ? void 0 : order.billing;
63
+ let { first_name: shipFirstName, last_name: shipLastName, address_1: shipAddress1, address_2: shipAddress2, address_3: shipAddress3, address_4: shipAddress4, address_5: shipAddress5, city: shipCity, postcode: shipPostalCode, country: shipCountry, phone: shipPhone1, phone_2: shipPhone2 } = order.shipping;
64
+ let orderPackage = (order === null || order === void 0 ? void 0 : order.orderPackage) || {};
65
+ let orderItems = order.orderItems.map(item => {
66
+ let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item;
67
+ return {
68
+ id,
69
+ variationId,
70
+ currency: order.orderShipping.collectionCurrency,
71
+ createdAt: order.orderCreatedAt,
72
+ updatedAt: order.orderUpdatedAt,
73
+ charges: [
74
+ {
75
+ name: 'CHARGES_MARKETING',
76
+ grossAmount: 0,
77
+ nettAmount: 0
78
+ },
79
+ {
80
+ name: 'CLAIMS_DAMAGE',
81
+ grossAmount: 0,
82
+ nettAmount: 0
83
+ },
84
+ {
85
+ name: 'CLAIMS_LOST',
86
+ grossAmount: 0,
87
+ nettAmount: 0
88
+ },
89
+ {
90
+ name: 'COMMISSION_PLATFORM',
91
+ grossAmount: 0,
92
+ nettAmount: 0
93
+ },
94
+ {
95
+ name: 'DEPOSIT_PRESALE',
96
+ grossAmount: 0,
97
+ nettAmount: 0
98
+ },
99
+ {
100
+ name: 'FEE_MISCELLANEOUS',
101
+ grossAmount: 0,
102
+ nettAmount: 0
103
+ },
104
+ {
105
+ name: 'FEE_TRANSACTION',
106
+ grossAmount: 0,
107
+ nettAmount: 0
108
+ },
109
+ {
110
+ name: 'PRICE_NORMAL_SELLING',
111
+ grossAmount: total,
112
+ nettAmount: subtotal
113
+ },
114
+ {
115
+ name: 'PRICE_RECOMMENDED_RETAIL',
116
+ grossAmount: 0,
117
+ nettAmount: 0
118
+ },
119
+ {
120
+ name: 'PROMOTIONS_CUSTOMER_RECEIVED',
121
+ grossAmount: 0,
122
+ nettAmount: 0
123
+ },
124
+ {
125
+ name: 'PROMOTIONS_REBATE_PLATFORM',
126
+ grossAmount: 0,
127
+ nettAmount: 0
128
+ },
129
+ {
130
+ name: 'PROMOTIONS_REBATE_SELLER',
131
+ grossAmount: 0,
132
+ nettAmount: 0
133
+ },
134
+ {
135
+ name: 'REVERSAL_CHARGES_MARKETING',
136
+ grossAmount: 0,
137
+ nettAmount: 0
138
+ },
139
+ {
140
+ name: 'REVERSAL_COMMISSION',
141
+ grossAmount: 0,
142
+ nettAmount: 0
143
+ },
144
+ {
145
+ name: 'REVERSAL_FEE_MISCELLANEOUS',
146
+ grossAmount: 0,
147
+ nettAmount: 0
148
+ },
149
+ {
150
+ name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
151
+ grossAmount: 0,
152
+ nettAmount: 0
153
+ },
154
+ {
155
+ name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
156
+ grossAmount: 0,
157
+ nettAmount: 0
158
+ },
159
+ {
160
+ name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
161
+ grossAmount: 0,
162
+ nettAmount: 0
163
+ },
164
+ {
165
+ name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
166
+ grossAmount: 0,
167
+ nettAmount: 0
168
+ },
169
+ {
170
+ name: 'REVERSAL_SHIPPING_SELLER_PAID',
171
+ grossAmount: 0,
172
+ nettAmount: 0
173
+ },
174
+ {
175
+ name: 'SHIPPING_COST_TOTAL',
176
+ grossAmount: 0,
177
+ nettAmount: 0
178
+ },
179
+ {
180
+ name: 'SHIPPING_CUSTOMER_PAID',
181
+ grossAmount: 0,
182
+ nettAmount: 0
183
+ },
184
+ {
185
+ name: 'SHIPPING_REBATE_PLATFORM',
186
+ grossAmount: 0,
187
+ nettAmount: 0
188
+ },
189
+ {
190
+ name: 'SHIPPING_SELLER_PAID',
191
+ grossAmount: 0,
192
+ nettAmount: 0
193
+ },
194
+ {
195
+ name: 'TAXES',
196
+ grossAmount: totalTax,
197
+ nettAmount: subtotalTax
198
+ },
199
+ {
200
+ name: 'VOUCHERS_CUSTOMER_RECEIVED',
201
+ grossAmount: 0,
202
+ nettAmount: 0
203
+ },
204
+ {
205
+ name: 'VOUCHERS_REBATE_PLATFORM',
206
+ grossAmount: 0,
207
+ nettAmount: 0
208
+ },
209
+ {
210
+ name: 'VOUCHERS_REBATE_SELLER',
211
+ grossAmount: 0,
212
+ nettAmount: 0
213
+ }
214
+ ],
215
+ slaExpiresAt,
216
+ qty
217
+ };
218
+ });
219
+ let mappedOrderItems = [];
220
+ orderItems.map(oi => {
221
+ for (let i = 0; i < oi.qty; i++) {
222
+ let orderLine;
223
+ if (orderLineList) {
224
+ orderLine = (orderLineList === null || orderLineList === void 0 ? void 0 : orderLineList.find(ol => ol.sku_id == oi.variationId)) || null;
225
+ orderLineList = orderLineList.filter(ol => ol.order_line_id != orderLine.order_line_id);
226
+ }
227
+ mappedOrderItems.push(Object.assign(Object.assign({}, oi), { id: orderLine ? orderLine.order_line_id : `${oi.id}-${i + 1}` }));
228
+ }
229
+ });
68
230
  return {
231
+ custFirstName,
232
+ custLastName,
233
+ createdAt,
234
+ updatedAt,
69
235
  id,
70
- variationId,
71
- currency: order.orderShipping.collectionCurrency,
72
- createdAt: order.orderCreatedAt,
73
- updatedAt: order.orderUpdatedAt,
74
- charges: [
75
- {
76
- name: 'CHARGES_MARKETING',
77
- grossAmount: 0,
78
- nettAmount: 0
79
- },
80
- {
81
- name: 'CLAIMS_DAMAGE',
82
- grossAmount: 0,
83
- nettAmount: 0
84
- },
85
- {
86
- name: 'CLAIMS_LOST',
87
- grossAmount: 0,
88
- nettAmount: 0
89
- },
90
- {
91
- name: 'COMMISSION_PLATFORM',
92
- grossAmount: 0,
93
- nettAmount: 0
94
- },
95
- {
96
- name: 'DEPOSIT_PRESALE',
97
- grossAmount: 0,
98
- nettAmount: 0
99
- },
100
- {
101
- name: 'FEE_MISCELLANEOUS',
102
- grossAmount: 0,
103
- nettAmount: 0
104
- },
105
- {
106
- name: 'FEE_TRANSACTION',
107
- grossAmount: 0,
108
- nettAmount: 0
109
- },
110
- {
111
- name: 'PRICE_NORMAL_SELLING',
112
- grossAmount: total,
113
- nettAmount: subtotal
114
- },
115
- {
116
- name: 'PRICE_RECOMMENDED_RETAIL',
117
- grossAmount: 0,
118
- nettAmount: 0
119
- },
120
- {
121
- name: 'PROMOTIONS_CUSTOMER_RECEIVED',
122
- grossAmount: 0,
123
- nettAmount: 0
124
- },
125
- {
126
- name: 'PROMOTIONS_REBATE_PLATFORM',
127
- grossAmount: 0,
128
- nettAmount: 0
129
- },
130
- {
131
- name: 'PROMOTIONS_REBATE_SELLER',
132
- grossAmount: 0,
133
- nettAmount: 0
134
- },
135
- {
136
- name: 'REVERSAL_CHARGES_MARKETING',
137
- grossAmount: 0,
138
- nettAmount: 0
139
- },
140
- {
141
- name: 'REVERSAL_COMMISSION',
142
- grossAmount: 0,
143
- nettAmount: 0
144
- },
145
- {
146
- name: 'REVERSAL_FEE_MISCELLANEOUS',
147
- grossAmount: 0,
148
- nettAmount: 0
149
- },
150
- {
151
- name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
152
- grossAmount: 0,
153
- nettAmount: 0
154
- },
155
- {
156
- name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
157
- grossAmount: 0,
158
- nettAmount: 0
159
- },
160
- {
161
- name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
162
- grossAmount: 0,
163
- nettAmount: 0
164
- },
165
- {
166
- name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
167
- grossAmount: 0,
168
- nettAmount: 0
169
- },
170
- {
171
- name: 'REVERSAL_SHIPPING_SELLER_PAID',
172
- grossAmount: 0,
173
- nettAmount: 0
174
- },
175
- {
176
- name: 'SHIPPING_COST_TOTAL',
177
- grossAmount: 0,
178
- nettAmount: 0
179
- },
180
- {
181
- name: 'SHIPPING_CUSTOMER_PAID',
182
- grossAmount: 0,
183
- nettAmount: 0
184
- },
185
- {
186
- name: 'SHIPPING_REBATE_PLATFORM',
187
- grossAmount: 0,
188
- nettAmount: 0
189
- },
190
- {
191
- name: 'SHIPPING_SELLER_PAID',
192
- grossAmount: 0,
193
- nettAmount: 0
194
- },
195
- {
196
- name: 'TAXES',
197
- grossAmount: totalTax,
198
- nettAmount: subtotalTax
199
- },
200
- {
201
- name: 'VOUCHERS_CUSTOMER_RECEIVED',
202
- grossAmount: 0,
203
- nettAmount: 0
204
- },
205
- {
206
- name: 'VOUCHERS_REBATE_PLATFORM',
207
- grossAmount: 0,
208
- nettAmount: 0
209
- },
210
- {
211
- name: 'VOUCHERS_REBATE_SELLER',
212
- grossAmount: 0,
213
- nettAmount: 0
214
- }
215
- ],
216
- slaExpiresAt,
217
- qty
236
+ sellercraftDisplayOrderNo,
237
+ billFirstName,
238
+ billLastName,
239
+ billAddress1: (billAddress1 === null || billAddress1 === void 0 ? void 0 : billAddress1.toString()) || (shipAddress1 === null || shipAddress1 === void 0 ? void 0 : shipAddress1.toString()),
240
+ billAddress2: billAddress2 || shipAddress2,
241
+ billAddress3: billAddress3 || shipAddress3,
242
+ billAddress4: billAddress4 || shipAddress4,
243
+ billAddress5: billAddress5 || shipAddress5,
244
+ billCity: billCity || shipCity,
245
+ billPostalCode: billPostalCode || shipPostalCode,
246
+ billCountry: billCountry || shipCountry,
247
+ billPhone1: billPhone1 || shipPhone1,
248
+ billPhone2: billPhone2 || shipPhone2,
249
+ shipFirstName,
250
+ shipLastName,
251
+ shipAddress1: shipAddress1 === null || shipAddress1 === void 0 ? void 0 : shipAddress1.toString(),
252
+ shipAddress2,
253
+ shipAddress3,
254
+ shipAddress4,
255
+ shipAddress5,
256
+ shipCity,
257
+ shipPostalCode,
258
+ shipCountry,
259
+ shipPhone1,
260
+ shipPhone2,
261
+ mappedOrderItems,
262
+ channelShopId,
263
+ organisationId,
264
+ status: sellercraftStatus || status,
265
+ isSOF: isSOF ? isSOF : false,
266
+ orderPackage,
267
+ charges: getOrderCharges(mappedOrderItems)
218
268
  };
219
269
  });
220
- let mappedOrderItems = [];
221
- orderItems.map(oi => {
222
- for (let i = 0; i < oi.qty; i++) {
223
- mappedOrderItems.push(Object.assign(Object.assign({}, oi), { id: `${oi.id}-${i + 1}` }));
224
- }
225
- });
226
- return {
227
- custFirstName,
228
- custLastName,
229
- createdAt,
230
- updatedAt,
231
- id,
232
- billFirstName,
233
- billLastName,
234
- billAddress1: billAddress1.toString() || shipAddress1.toString(),
235
- billAddress2: billAddress2 || shipAddress2,
236
- billAddress3: billAddress3 || shipAddress3,
237
- billAddress4: billAddress4 || shipAddress4,
238
- billAddress5: billAddress5 || shipAddress5,
239
- billCity: billCity || shipCity,
240
- billPostalCode: billPostalCode || shipPostalCode,
241
- billCountry: billCountry || shipCountry,
242
- billPhone1: billPhone1 || shipPhone1,
243
- billPhone2: billPhone2 || shipPhone2,
244
- shipFirstName,
245
- shipLastName,
246
- shipAddress1: shipAddress1.toString(),
247
- shipAddress2,
248
- shipAddress3,
249
- shipAddress4,
250
- shipAddress5,
251
- shipCity,
252
- shipPostalCode,
253
- shipCountry,
254
- shipPhone1,
255
- shipPhone2,
256
- mappedOrderItems,
257
- channelShopId,
258
- organisationId,
259
- status: sellercraftStatus || status,
260
- isSOF: isSOF ? isSOF : false,
261
- orderPackage,
262
- charges: getOrderCharges(mappedOrderItems)
263
- };
264
- });
265
- if (mappedOrderResult.length > 0) {
266
- while (mappedOrderResult.length > 0) {
267
- let spliceResult = mappedOrderResult.splice(0, mappedOrderResult.length >= 20 ? 20 : mappedOrderResult.length);
268
- try {
269
- await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, {
270
- orders: spliceResult
271
- });
272
- }
273
- catch (e) { }
274
- await Promise.all(spliceResult.map(async (result) => {
275
- var _a;
276
- if (!(result === null || result === void 0 ? void 0 : result.isSOF) && ((_a = result === null || result === void 0 ? void 0 : result.orderPackage) === null || _a === void 0 ? void 0 : _a.packageId)) {
277
- let orderPackage = result.orderPackage;
278
- let newOrderPackage = {
279
- channelShopId,
280
- nativeOrderId: result.id,
281
- nativePackageId: orderPackage.packageId,
282
- shippingTrackingCode: orderPackage.trackingNumber,
283
- shippingTypeValue: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.shippingType)
284
- ? orderPackage.shippingType
285
- : constants_1.SHIPPING_TYPE.DROP_SHIPPING,
286
- warehouseCode: constants_1.SHIPPING_TYPE.DROP_SHIPPING,
287
- shipper: {
288
- name: orderPackage.shippingProvider,
289
- isCodSupported: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.isCodSupport) ? orderPackage.isCodSupport : false
290
- },
291
- documents: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.orderDocument) || [],
292
- shipperLastMile: {
293
- name: orderPackage.shippingProvider,
294
- isCodSupported: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.isCodSupport) ? orderPackage.isCodSupport : false
295
- },
296
- orderItemIds: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.orderListIdList)
297
- ? orderPackage.orderListIdList
298
- : result.mappedOrderItems.map(orderItem => orderItem.id)
299
- };
300
- try {
301
- await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrderPackage(sellercraftStore, newOrderPackage);
302
- }
303
- catch (e) { }
270
+ if (mappedOrderResult.length > 0) {
271
+ while (mappedOrderResult.length > 0) {
272
+ let spliceResult = mappedOrderResult.splice(0, mappedOrderResult.length >= 20 ? 20 : mappedOrderResult.length);
273
+ try {
274
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, {
275
+ orders: spliceResult
276
+ });
277
+ }
278
+ catch (e) {
279
+ errors.push({
280
+ name: 'Order Ingestion Error',
281
+ msg: JSON.stringify(e) || {}
282
+ });
304
283
  }
305
- }));
284
+ await Promise.all(spliceResult.map(async (result) => {
285
+ var _a;
286
+ if (!(result === null || result === void 0 ? void 0 : result.isSOF) && ((_a = result === null || result === void 0 ? void 0 : result.orderPackage) === null || _a === void 0 ? void 0 : _a.packageId)) {
287
+ let orderPackage = result.orderPackage;
288
+ let newOrderPackage = {
289
+ channelShopId,
290
+ nativeOrderId: result.id,
291
+ nativePackageId: orderPackage.packageId,
292
+ shippingTrackingCode: orderPackage.trackingNumber,
293
+ shippingTypeValue: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.shippingType)
294
+ ? orderPackage.shippingType
295
+ : constants_1.SHIPPING_TYPE.DROP_SHIPPING,
296
+ warehouseCode: constants_1.SHIPPING_TYPE.DROP_SHIPPING,
297
+ shipper: {
298
+ name: orderPackage.shippingProvider,
299
+ isCodSupported: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.isCodSupport) ? orderPackage.isCodSupport : false
300
+ },
301
+ documents: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.orderDocument) || [],
302
+ shipperLastMile: {
303
+ name: orderPackage.shippingProvider,
304
+ isCodSupported: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.isCodSupport) ? orderPackage.isCodSupport : false
305
+ },
306
+ orderItemIds: (orderPackage === null || orderPackage === void 0 ? void 0 : orderPackage.orderListIdList)
307
+ ? orderPackage.orderListIdList
308
+ : result.mappedOrderItems.map(orderItem => orderItem.id)
309
+ };
310
+ try {
311
+ await sellercraft_channel_integration_api_1.SellercraftChannelIntegrationAPI.ingestChannelOrderPackage(sellercraftStore, newOrderPackage);
312
+ }
313
+ catch (e) {
314
+ errors.push({
315
+ name: 'Order Package Ingestion Error',
316
+ msg: JSON.stringify(e) || {}
317
+ });
318
+ }
319
+ }
320
+ }));
321
+ }
306
322
  }
323
+ if (more)
324
+ page++;
325
+ hasMorePage = more;
326
+ cursor = nextCursor;
307
327
  }
308
328
  }
309
- catch (e) { }
329
+ catch (e) {
330
+ errors.push({
331
+ name: 'Order Processing / Mapping Error',
332
+ msg: JSON.stringify(e) || {}
333
+ });
334
+ }
310
335
  }
311
336
  }
312
- catch (e) { }
337
+ catch (e) {
338
+ errors.push({
339
+ name: 'Store Error',
340
+ msg: JSON.stringify(e) || {}
341
+ });
342
+ }
343
+ }
344
+ if (errors.length > 1 && airflow) {
345
+ throw errors;
313
346
  }
314
347
  return true;
315
348
  }
@@ -321,8 +354,11 @@ tslib_1.__decorate([
321
354
  tslib_1.__param(2, (0, type_graphql_1.Arg)('toCreatedDate', { nullable: true })),
322
355
  tslib_1.__param(3, (0, type_graphql_1.Arg)('fromUpdatedDate', { nullable: true })),
323
356
  tslib_1.__param(4, (0, type_graphql_1.Arg)('toUpdatedDate', { nullable: true })),
357
+ tslib_1.__param(5, (0, type_graphql_1.Arg)('channelId', { nullable: true })),
358
+ tslib_1.__param(6, (0, type_graphql_1.Arg)('shopId', { nullable: true })),
359
+ tslib_1.__param(7, (0, type_graphql_1.Arg)('airflow', { nullable: true })),
324
360
  tslib_1.__metadata("design:type", Function),
325
- tslib_1.__metadata("design:paramtypes", [Object, String, String, String, String]),
361
+ tslib_1.__metadata("design:paramtypes", [Object, String, String, String, String, String, String, Boolean]),
326
362
  tslib_1.__metadata("design:returntype", Promise)
327
363
  ], MarketplaceChannelOrderMutation.prototype, "syncAllMarketplaceChannelOrders", null);
328
364
  MarketplaceChannelOrderMutation = tslib_1.__decorate([