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