@things-factory/integration-sellercraft 4.2.2 → 4.2.7

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.
Files changed (25) hide show
  1. package/dist-server/constants/order-status-mapping.js +13 -3
  2. package/dist-server/constants/order-status-mapping.js.map +1 -1
  3. package/dist-server/constants/platform.js +2 -1
  4. package/dist-server/constants/platform.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +1 -1
  6. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +25 -8
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +8 -4
  10. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  11. package/dist-server/routers/sellercraft-router.js +2 -1
  12. package/dist-server/routers/sellercraft-router.js.map +1 -1
  13. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +253 -231
  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 +48 -23
  16. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  17. package/package.json +3 -3
  18. package/server/constants/order-status-mapping.ts +13 -3
  19. package/server/constants/platform.ts +2 -1
  20. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +1 -1
  21. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +34 -15
  22. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +8 -4
  23. package/server/routers/sellercraft-router.ts +2 -1
  24. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +305 -270
  25. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +47 -26
@@ -1,11 +1,11 @@
1
1
  import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
2
2
  import { getRepository } from 'typeorm'
3
3
 
4
- import { MarketplaceChannel } from './marketplace-channel'
5
-
6
4
  import { config } from '@things-factory/env'
7
5
  import { StoreAPI } from '@things-factory/integration-marketplace'
6
+
8
7
  import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
8
+ import { MarketplaceChannel } from './marketplace-channel'
9
9
 
10
10
  @Resolver()
11
11
  export class MarketplaceChannelOrderMutation {
@@ -21,293 +21,328 @@ export class MarketplaceChannelOrderMutation {
21
21
  const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find()
22
22
 
23
23
  for (var i = 0; i < channels.length; i++) {
24
- var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channels[i].channelId
25
- const channelResponse: any = await fetch(channelsFullPath, {
26
- method: 'get',
27
- headers: {
28
- 'Content-Type': 'application/json',
29
- 'x-api-key': apiKey
24
+ try {
25
+ var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channels[i].channelId
26
+ const channelResponse: any = await fetch(channelsFullPath, {
27
+ method: 'get',
28
+ headers: {
29
+ 'Content-Type': 'application/json',
30
+ 'x-api-key': apiKey
31
+ }
32
+ })
33
+
34
+ if (!channelResponse.ok) {
35
+ throw new Error(channelResponse)
30
36
  }
31
- })
37
+ var shopsResponse = await channelResponse.json()
38
+ var shops = shopsResponse.shops
32
39
 
33
- if (!channelResponse.ok) {
34
- throw new Error(channelResponse)
35
- }
36
- var shopsResponse = await channelResponse.json()
37
- var shops = shopsResponse.shops
40
+ for (var j = 0; j < shops.length; j++) {
41
+ var store = {
42
+ accessKey: shops[j]?.credential?.consumer_key || '',
43
+ accessSecret: shops[j]?.credential?.consumer_secret || '',
44
+ storeURL: shops[j]?.credential?.store_url || '',
45
+ platform: channels[i].name,
46
+ accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
47
+ channelShopId: shops[j]?.channel_shop_id
48
+ }
38
49
 
39
- for (var j = 0; j < shops.length; j++) {
40
- var store = {
41
- accessKey: shops[j].credential.consumer_key,
42
- accessSecret: shops[j].credential.consumer_secret,
43
- storeURL: shops[j].credential.store_url,
44
- platform: channels[i].name,
45
- accessToken: shops[j].credential.access_token // Magento+
46
- }
50
+ // let countryCode = shops[j].country_code
51
+ // let channelCode = shops[j].org_prefix
52
+ let organisationId = shops[j].account_id
53
+ let channelShopId = shops[j].channel_shop_id
47
54
 
48
- // let countryCode = shops[j].country_code
49
- // let channelCode = shops[j].org_prefix
50
- let organisationId = shops[j].account_id
51
- let channelShopId = shops[j].channel_shop_id
55
+ let orderResult = []
56
+ let page: number = 1
57
+ let hasMorePage: boolean = true
58
+ let lastOrderId: string
59
+ let nextCursor: string
60
+ var limit: number = 50
52
61
 
53
- const orderReq = {
54
- fromDate: fromDate,
55
- toDate: toDate
56
- }
57
- const orderResult = await StoreAPI.getStoreOrders(store, orderReq)
62
+ while (hasMorePage) {
63
+ const {
64
+ results: marketplaceOrders,
65
+ more,
66
+ nextCursor
67
+ } = await StoreAPI.getStoreOrders(store, {
68
+ fromDate,
69
+ toDate,
70
+ pagination: { page, limit },
71
+ lastOrderId,
72
+ nextCursor: lastOrderId
73
+ })
58
74
 
59
- var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
75
+ orderResult.push(...marketplaceOrders)
60
76
 
61
- let mappedOrderResult = orderResult.results.map(order => {
62
- let {
63
- firstName: custFirstName,
64
- lastName: custLastName,
65
- orderCreatedAt: createdAt,
66
- orderUpdatedAt: updatedAt,
67
- orderNo: id,
68
- status
69
- } = order
77
+ if (more) page++
78
+ hasMorePage = more
79
+ lastOrderId = nextCursor
80
+ }
70
81
 
71
- let {
72
- first_name: billFirstName,
73
- last_name: billLastName,
74
- address_1: billAddress1,
75
- address_2: billAddress2,
76
- address_3: billAddress3,
77
- address_4: billAddress4,
78
- address_5: billAddress5,
79
- city: billCity,
80
- postcode: billPostalCode,
81
- country: billCountry,
82
- phone: billPhone1,
83
- phone_2: billPhone2
84
- } = order?.billing
82
+ var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
85
83
 
86
- let {
87
- first_name: shipFirstName,
88
- last_name: shipLastName,
89
- address_1: shipAddress1,
90
- address_2: shipAddress2,
91
- address_3: shipAddress3,
92
- address_4: shipAddress4,
93
- address_5: shipAddress5,
94
- city: shipCity,
95
- postcode: shipPostalCode,
96
- country: shipCountry,
97
- phone: shipPhone1,
98
- phone_2: shipPhone2
99
- } = order.shipping
84
+ let mappedOrderResult = orderResult.map(order => {
85
+ let {
86
+ firstName: custFirstName,
87
+ lastName: custLastName,
88
+ orderCreatedAt: createdAt,
89
+ orderUpdatedAt: updatedAt,
90
+ orderNo: id,
91
+ status
92
+ } = order
100
93
 
101
- let orderItems = order.orderItems.map(item => {
102
- let { name: id, variationId: variationId, slaExpiresAt, total, totalTax, subtotal, subtotalTax, qty } = item
94
+ let {
95
+ first_name: billFirstName,
96
+ last_name: billLastName,
97
+ address_1: billAddress1,
98
+ address_2: billAddress2,
99
+ address_3: billAddress3,
100
+ address_4: billAddress4,
101
+ address_5: billAddress5,
102
+ city: billCity,
103
+ postcode: billPostalCode,
104
+ country: billCountry,
105
+ phone: billPhone1,
106
+ phone_2: billPhone2
107
+ } = order?.billing
108
+
109
+ let {
110
+ first_name: shipFirstName,
111
+ last_name: shipLastName,
112
+ address_1: shipAddress1,
113
+ address_2: shipAddress2,
114
+ address_3: shipAddress3,
115
+ address_4: shipAddress4,
116
+ address_5: shipAddress5,
117
+ city: shipCity,
118
+ postcode: shipPostalCode,
119
+ country: shipCountry,
120
+ phone: shipPhone1,
121
+ phone_2: shipPhone2
122
+ } = order.shipping
123
+
124
+ let orderItems = order.orderItems.map(item => {
125
+ let {
126
+ name: id,
127
+ variationId: variationId,
128
+ slaExpiresAt,
129
+ total,
130
+ totalTax,
131
+ subtotal,
132
+ subtotalTax,
133
+ qty
134
+ } = item
135
+
136
+ return {
137
+ id,
138
+ variationId,
139
+ currency: order.orderShipping.collectionCurrency,
140
+ createdAt: order.orderCreatedAt,
141
+ updatedAt: order.orderUpdatedAt,
142
+ charges: [
143
+ {
144
+ name: 'CHARGES_MARKETING',
145
+ grossAmount: 0,
146
+ nettAmount: 0
147
+ },
148
+ {
149
+ name: 'CLAIMS_DAMAGE',
150
+ grossAmount: 0,
151
+ nettAmount: 0
152
+ },
153
+ {
154
+ name: 'CLAIMS_LOST',
155
+ grossAmount: 0,
156
+ nettAmount: 0
157
+ },
158
+ {
159
+ name: 'COMMISSION_PLATFORM',
160
+ grossAmount: 0,
161
+ nettAmount: 0
162
+ },
163
+ {
164
+ name: 'DEPOSIT_PRESALE',
165
+ grossAmount: 0,
166
+ nettAmount: 0
167
+ },
168
+ {
169
+ name: 'FEE_MISCELLANEOUS',
170
+ grossAmount: 0,
171
+ nettAmount: 0
172
+ },
173
+ {
174
+ name: 'FEE_TRANSACTION',
175
+ grossAmount: 0,
176
+ nettAmount: 0
177
+ },
178
+ {
179
+ name: 'PRICE_NORMAL_SELLING',
180
+ grossAmount: total,
181
+ nettAmount: subtotal
182
+ },
183
+ {
184
+ name: 'PRICE_RECOMMENDED_RETAIL',
185
+ grossAmount: 0,
186
+ nettAmount: 0
187
+ },
188
+ {
189
+ name: 'PROMOTIONS_CUSTOMER_RECEIVED',
190
+ grossAmount: 0,
191
+ nettAmount: 0
192
+ },
193
+ {
194
+ name: 'PROMOTIONS_REBATE_PLATFORM',
195
+ grossAmount: 0,
196
+ nettAmount: 0
197
+ },
198
+ {
199
+ name: 'PROMOTIONS_REBATE_SELLER',
200
+ grossAmount: 0,
201
+ nettAmount: 0
202
+ },
203
+ {
204
+ name: 'REVERSAL_CHARGES_MARKETING',
205
+ grossAmount: 0,
206
+ nettAmount: 0
207
+ },
208
+ {
209
+ name: 'REVERSAL_COMMISSION',
210
+ grossAmount: 0,
211
+ nettAmount: 0
212
+ },
213
+ {
214
+ name: 'REVERSAL_FEE_MISCELLANEOUS',
215
+ grossAmount: 0,
216
+ nettAmount: 0
217
+ },
218
+ {
219
+ name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
220
+ grossAmount: 0,
221
+ nettAmount: 0
222
+ },
223
+ {
224
+ name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
225
+ grossAmount: 0,
226
+ nettAmount: 0
227
+ },
228
+ {
229
+ name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
230
+ grossAmount: 0,
231
+ nettAmount: 0
232
+ },
233
+ {
234
+ name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
235
+ grossAmount: 0,
236
+ nettAmount: 0
237
+ },
238
+ {
239
+ name: 'REVERSAL_SHIPPING_SELLER_PAID',
240
+ grossAmount: 0,
241
+ nettAmount: 0
242
+ },
243
+ {
244
+ name: 'SHIPPING_COST_TOTAL',
245
+ grossAmount: 0,
246
+ nettAmount: 0
247
+ },
248
+ {
249
+ name: 'SHIPPING_CUSTOMER_PAID',
250
+ grossAmount: 0,
251
+ nettAmount: 0
252
+ },
253
+ {
254
+ name: 'SHIPPING_REBATE_PLATFORM',
255
+ grossAmount: 0,
256
+ nettAmount: 0
257
+ },
258
+ {
259
+ name: 'SHIPPING_SELLER_PAID',
260
+ grossAmount: 0,
261
+ nettAmount: 0
262
+ },
263
+ {
264
+ name: 'TAXES',
265
+ grossAmount: totalTax,
266
+ nettAmount: subtotalTax
267
+ },
268
+ {
269
+ name: 'VOUCHERS_CUSTOMER_RECEIVED',
270
+ grossAmount: 0,
271
+ nettAmount: 0
272
+ },
273
+ {
274
+ name: 'VOUCHERS_REBATE_PLATFORM',
275
+ grossAmount: 0,
276
+ nettAmount: 0
277
+ },
278
+ {
279
+ name: 'VOUCHERS_REBATE_SELLER',
280
+ grossAmount: 0,
281
+ nettAmount: 0
282
+ }
283
+ ],
284
+ slaExpiresAt,
285
+ qty
286
+ }
287
+ })
288
+
289
+ let mappedOrderItems = []
290
+ orderItems.map(oi => {
291
+ for (let i = 0; i < oi.qty; i++) {
292
+ mappedOrderItems.push({
293
+ ...oi,
294
+ id: `${oi.id}-${i + 1}`
295
+ })
296
+ }
297
+ })
103
298
 
104
299
  return {
300
+ custFirstName,
301
+ custLastName,
302
+ createdAt,
303
+ updatedAt,
105
304
  id,
106
- variationId,
107
- currency: order.orderShipping.collectionCurrency,
108
- createdAt: order.orderCreatedAt,
109
- updatedAt: order.orderUpdatedAt,
110
- charges: [
111
- {
112
- name: 'CHARGES_MARKETING',
113
- grossAmount: 0,
114
- nettAmount: 0
115
- },
116
- {
117
- name: 'CLAIMS_DAMAGE',
118
- grossAmount: 0,
119
- nettAmount: 0
120
- },
121
- {
122
- name: 'CLAIMS_LOST',
123
- grossAmount: 0,
124
- nettAmount: 0
125
- },
126
- {
127
- name: 'COMMISSION_PLATFORM',
128
- grossAmount: 0,
129
- nettAmount: 0
130
- },
131
- {
132
- name: 'DEPOSIT_PRESALE',
133
- grossAmount: 0,
134
- nettAmount: 0
135
- },
136
- {
137
- name: 'FEE_MISCELLANEOUS',
138
- grossAmount: 0,
139
- nettAmount: 0
140
- },
141
- {
142
- name: 'FEE_TRANSACTION',
143
- grossAmount: 0,
144
- nettAmount: 0
145
- },
146
- {
147
- name: 'PRICE_NORMAL_SELLING',
148
- grossAmount: total,
149
- nettAmount: subtotal
150
- },
151
- {
152
- name: 'PRICE_RECOMMENDED_RETAIL',
153
- grossAmount: 0,
154
- nettAmount: 0
155
- },
156
- {
157
- name: 'PROMOTIONS_CUSTOMER_RECEIVED',
158
- grossAmount: 0,
159
- nettAmount: 0
160
- },
161
- {
162
- name: 'PROMOTIONS_REBATE_PLATFORM',
163
- grossAmount: 0,
164
- nettAmount: 0
165
- },
166
- {
167
- name: 'PROMOTIONS_REBATE_SELLER',
168
- grossAmount: 0,
169
- nettAmount: 0
170
- },
171
- {
172
- name: 'REVERSAL_CHARGES_MARKETING',
173
- grossAmount: 0,
174
- nettAmount: 0
175
- },
176
- {
177
- name: 'REVERSAL_COMMISSION',
178
- grossAmount: 0,
179
- nettAmount: 0
180
- },
181
- {
182
- name: 'REVERSAL_FEE_MISCELLANEOUS',
183
- grossAmount: 0,
184
- nettAmount: 0
185
- },
186
- {
187
- name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
188
- grossAmount: 0,
189
- nettAmount: 0
190
- },
191
- {
192
- name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
193
- grossAmount: 0,
194
- nettAmount: 0
195
- },
196
- {
197
- name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
198
- grossAmount: 0,
199
- nettAmount: 0
200
- },
201
- {
202
- name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
203
- grossAmount: 0,
204
- nettAmount: 0
205
- },
206
- {
207
- name: 'REVERSAL_SHIPPING_SELLER_PAID',
208
- grossAmount: 0,
209
- nettAmount: 0
210
- },
211
- {
212
- name: 'SHIPPING_COST_TOTAL',
213
- grossAmount: 0,
214
- nettAmount: 0
215
- },
216
- {
217
- name: 'SHIPPING_CUSTOMER_PAID',
218
- grossAmount: 0,
219
- nettAmount: 0
220
- },
221
- {
222
- name: 'SHIPPING_REBATE_PLATFORM',
223
- grossAmount: 0,
224
- nettAmount: 0
225
- },
226
- {
227
- name: 'SHIPPING_SELLER_PAID',
228
- grossAmount: 0,
229
- nettAmount: 0
230
- },
231
- {
232
- name: 'TAXES',
233
- grossAmount: totalTax,
234
- nettAmount: subtotalTax
235
- },
236
- {
237
- name: 'VOUCHERS_CUSTOMER_RECEIVED',
238
- grossAmount: 0,
239
- nettAmount: 0
240
- },
241
- {
242
- name: 'VOUCHERS_REBATE_PLATFORM',
243
- grossAmount: 0,
244
- nettAmount: 0
245
- },
246
- {
247
- name: 'VOUCHERS_REBATE_SELLER',
248
- grossAmount: 0,
249
- nettAmount: 0
250
- }
251
- ],
252
- slaExpiresAt,
253
- qty
305
+ billFirstName,
306
+ billLastName,
307
+ billAddress1: billAddress1.toString() || shipAddress1.toString(),
308
+ billAddress2: billAddress2 || shipAddress2,
309
+ billAddress3: billAddress3 || shipAddress3,
310
+ billAddress4: billAddress4 || shipAddress4,
311
+ billAddress5: billAddress5 || shipAddress5,
312
+ billCity: billCity || shipCity,
313
+ billPostalCode: billPostalCode || shipPostalCode,
314
+ billCountry: billCountry || shipCountry,
315
+ billPhone1: billPhone1 || shipPhone1,
316
+ billPhone2: billPhone2 || shipPhone2,
317
+ shipFirstName,
318
+ shipLastName,
319
+ shipAddress1: shipAddress1.toString(),
320
+ shipAddress2,
321
+ shipAddress3,
322
+ shipAddress4,
323
+ shipAddress5,
324
+ shipCity,
325
+ shipPostalCode,
326
+ shipCountry,
327
+ shipPhone1,
328
+ shipPhone2,
329
+ mappedOrderItems,
330
+ channelShopId,
331
+ organisationId,
332
+ status,
333
+ charges: getOrderCharges(mappedOrderItems)
254
334
  }
255
335
  })
256
336
 
257
- let mappedOrderItems = []
258
- orderItems.map(oi => {
259
- for (let i = 0; i < oi.qty; i++) {
260
- mappedOrderItems.push({
261
- ...oi,
262
- id: `${oi.id}-${i + 1}`
263
- })
264
- }
265
- })
266
-
267
- return {
268
- custFirstName,
269
- custLastName,
270
- createdAt,
271
- updatedAt,
272
- id,
273
- billFirstName,
274
- billLastName,
275
- billAddress1: billAddress1.toString() || shipAddress1.toString(),
276
- billAddress2: billAddress2 || shipAddress2,
277
- billAddress3: billAddress3 || shipAddress3,
278
- billAddress4: billAddress4 || shipAddress4,
279
- billAddress5: billAddress5 || shipAddress5,
280
- billCity: billCity || shipCity,
281
- billPostalCode: billPostalCode || shipPostalCode,
282
- billCountry: billCountry || shipCountry,
283
- billPhone1: billPhone1 || shipPhone1,
284
- billPhone2: billPhone2 || shipPhone2,
285
- shipFirstName,
286
- shipLastName,
287
- shipAddress1: shipAddress1.toString(),
288
- shipAddress2,
289
- shipAddress3,
290
- shipAddress4,
291
- shipAddress5,
292
- shipCity,
293
- shipPostalCode,
294
- shipCountry,
295
- shipPhone1,
296
- shipPhone2,
297
- mappedOrderItems,
298
- channelShopId,
299
- organisationId,
300
- status,
301
- charges: getOrderCharges(mappedOrderItems)
337
+ if (mappedOrderResult.length > 0) {
338
+ await SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, { orders: mappedOrderResult })
302
339
  }
303
- })
304
-
305
- if (mappedOrderResult.length > 0) {
306
- await SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, { orders: mappedOrderResult })
307
340
  }
308
- }
309
341
 
310
- return true
342
+ return true
343
+ } catch (e) {
344
+ debugger
345
+ }
311
346
  }
312
347
  }
313
348
  }