@things-factory/integration-sellercraft 5.0.0-alpha.50 → 5.0.0-alpha.54
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/constants/order-status-mapping.js +3 -0
- package/dist-server/constants/order-status-mapping.js.map +1 -1
- package/dist-server/constants/platform.js +2 -1
- package/dist-server/constants/platform.js.map +1 -1
- package/dist-server/controllers/sellercraft/sellercraft.js +2 -2
- package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/decorators.js +2 -0
- package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +5 -3
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +11 -4
- package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +85 -135
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +59 -57
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +162 -157
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-mutation.js +3 -6
- package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
- package/dist-server/utils/tokencraft-util.js +63 -0
- package/dist-server/utils/tokencraft-util.js.map +1 -0
- package/package.json +15 -15
- package/server/constants/order-status-mapping.ts +3 -0
- package/server/constants/platform.ts +2 -1
- package/server/controllers/sellercraft/sellercraft.ts +2 -2
- package/server/controllers/sellercraft-api/decorators.ts +3 -0
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +4 -3
- package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +9 -4
- package/server/routers/sellercraft-router.ts +91 -145
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +62 -56
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +186 -183
- package/server/service/sellercraft/sellercraft-mutation.ts +3 -3
- package/server/service/sellercraft/sellercraft-query.ts +1 -1
- package/server/utils/tokencraft-util.ts +60 -0
@@ -7,37 +7,26 @@ import { StoreAPI } from '@things-factory/integration-marketplace'
|
|
7
7
|
import { SHIPPING_TYPE } from '../../constants'
|
8
8
|
import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
|
9
9
|
import { MarketplaceChannel } from './marketplace-channel'
|
10
|
+
import { getShops } from '../../utils/tokencraft-util'
|
10
11
|
|
11
12
|
@Resolver()
|
12
13
|
export class MarketplaceChannelOrderMutation {
|
13
14
|
@Mutation(returns => Boolean)
|
14
15
|
async syncAllMarketplaceChannelOrders(
|
15
|
-
@
|
16
|
-
@Arg('
|
17
|
-
@
|
16
|
+
@Ctx() context: any,
|
17
|
+
@Arg('fromCreatedDate', { nullable: true }) fromCreatedDate?: string,
|
18
|
+
@Arg('toCreatedDate', { nullable: true }) toCreatedDate?: string,
|
19
|
+
@Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: string,
|
20
|
+
@Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string
|
18
21
|
): Promise<boolean> {
|
19
22
|
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
20
|
-
const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig
|
21
23
|
|
22
24
|
const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
|
23
25
|
|
24
26
|
for (var i = 0; i < channels.length; i++) {
|
25
27
|
try {
|
26
28
|
const channel: MarketplaceChannel = channels[i]
|
27
|
-
|
28
|
-
const channelResponse: any = await fetch(channelsFullPath, {
|
29
|
-
method: 'get',
|
30
|
-
headers: {
|
31
|
-
'Content-Type': 'application/json',
|
32
|
-
'x-api-key': apiKey
|
33
|
-
}
|
34
|
-
})
|
35
|
-
|
36
|
-
if (!channelResponse.ok) {
|
37
|
-
throw new Error(channelResponse)
|
38
|
-
}
|
39
|
-
var shopsResponse = await channelResponse.json()
|
40
|
-
var shops = shopsResponse.shops
|
29
|
+
let shops: any = await getShops(channel.channelId)
|
41
30
|
|
42
31
|
for (var j = 0; j < shops.length; j++) {
|
43
32
|
try {
|
@@ -47,7 +36,8 @@ export class MarketplaceChannelOrderMutation {
|
|
47
36
|
storeURL: shops[j]?.credential?.store_url || '',
|
48
37
|
platform: channel.name,
|
49
38
|
accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
|
50
|
-
channelShopId: shops[j]?.channel_shop_id
|
39
|
+
channelShopId: shops[j]?.channel_shop_id,
|
40
|
+
storeId: shops[j]?.credential?.store_url || ''
|
51
41
|
}
|
52
42
|
|
53
43
|
// let countryCode = shops[j].country_code
|
@@ -68,8 +58,10 @@ export class MarketplaceChannelOrderMutation {
|
|
68
58
|
more,
|
69
59
|
nextCursor
|
70
60
|
} = await StoreAPI.getStoreOrders(store, {
|
71
|
-
|
72
|
-
|
61
|
+
fromCreatedDate,
|
62
|
+
toCreatedDate,
|
63
|
+
fromUpdatedDate,
|
64
|
+
toUpdatedDate,
|
73
65
|
pagination: { page, limit },
|
74
66
|
lastOrderId,
|
75
67
|
nextCursor: cursor
|
@@ -85,13 +77,14 @@ export class MarketplaceChannelOrderMutation {
|
|
85
77
|
var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
|
86
78
|
|
87
79
|
let mappedOrderResult = orderResult.map(order => {
|
88
|
-
let id = store.platform == 'magento' ? order.name : order.orderNo
|
80
|
+
let id = store.platform == 'magento' || store.platform == 'shopify' ? order.name : order.orderNo
|
89
81
|
let {
|
90
82
|
firstName: custFirstName,
|
91
83
|
lastName: custLastName,
|
92
84
|
orderCreatedAt: createdAt,
|
93
85
|
orderUpdatedAt: updatedAt,
|
94
86
|
status,
|
87
|
+
sellercraftStatus,
|
95
88
|
isSOF
|
96
89
|
} = order
|
97
90
|
|
@@ -335,7 +328,7 @@ export class MarketplaceChannelOrderMutation {
|
|
335
328
|
mappedOrderItems,
|
336
329
|
channelShopId,
|
337
330
|
organisationId,
|
338
|
-
status,
|
331
|
+
status: sellercraftStatus || status,
|
339
332
|
isSOF: isSOF ? isSOF : false,
|
340
333
|
orderPackage,
|
341
334
|
charges: getOrderCharges(mappedOrderItems)
|
@@ -343,41 +336,54 @@ export class MarketplaceChannelOrderMutation {
|
|
343
336
|
})
|
344
337
|
|
345
338
|
if (mappedOrderResult.length > 0) {
|
346
|
-
|
347
|
-
|
348
|
-
|
339
|
+
while (mappedOrderResult.length > 0) {
|
340
|
+
let spliceResult = mappedOrderResult.splice(
|
341
|
+
0,
|
342
|
+
mappedOrderResult.length >= 20 ? 20 : mappedOrderResult.length
|
343
|
+
)
|
349
344
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
channelShopId,
|
356
|
-
nativeOrderId: result.id,
|
357
|
-
nativePackageId: orderPackage.packageId,
|
358
|
-
shippingTrackingCode: orderPackage.trackingNumber,
|
359
|
-
shippingTypeValue: orderPackage?.shippingType
|
360
|
-
? orderPackage.shippingType
|
361
|
-
: SHIPPING_TYPE.DROP_SHIPPING,
|
362
|
-
warehouseCode: SHIPPING_TYPE.DROP_SHIPPING,
|
363
|
-
shipper: {
|
364
|
-
name: orderPackage.shippingProvider,
|
365
|
-
isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
366
|
-
},
|
367
|
-
documents: orderPackage?.orderDocument || [],
|
368
|
-
shipperLastMile: {
|
369
|
-
name: orderPackage.shippingProvider,
|
370
|
-
isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
371
|
-
},
|
372
|
-
orderItemIds: orderPackage?.orderListIdList
|
373
|
-
? orderPackage.orderListIdList
|
374
|
-
: result.mappedOrderItems.map(orderItem => orderItem.id)
|
375
|
-
}
|
345
|
+
try {
|
346
|
+
await SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, {
|
347
|
+
orders: spliceResult
|
348
|
+
})
|
349
|
+
} catch (e) {}
|
376
350
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
351
|
+
await Promise.all(
|
352
|
+
spliceResult.map(async result => {
|
353
|
+
if (!result?.isSOF && result?.orderPackage?.packageId) {
|
354
|
+
let orderPackage: any = result.orderPackage
|
355
|
+
let newOrderPackage: any = {
|
356
|
+
channelShopId,
|
357
|
+
nativeOrderId: result.id,
|
358
|
+
nativePackageId: orderPackage.packageId,
|
359
|
+
shippingTrackingCode: orderPackage.trackingNumber,
|
360
|
+
shippingTypeValue: orderPackage?.shippingType
|
361
|
+
? orderPackage.shippingType
|
362
|
+
: SHIPPING_TYPE.DROP_SHIPPING,
|
363
|
+
warehouseCode: SHIPPING_TYPE.DROP_SHIPPING,
|
364
|
+
shipper: {
|
365
|
+
name: orderPackage.shippingProvider,
|
366
|
+
isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
367
|
+
},
|
368
|
+
documents: orderPackage?.orderDocument || [],
|
369
|
+
shipperLastMile: {
|
370
|
+
name: orderPackage.shippingProvider,
|
371
|
+
isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
|
372
|
+
},
|
373
|
+
orderItemIds: orderPackage?.orderListIdList
|
374
|
+
? orderPackage.orderListIdList
|
375
|
+
: result.mappedOrderItems.map(orderItem => orderItem.id)
|
376
|
+
}
|
377
|
+
try {
|
378
|
+
await SellercraftChannelIntegrationAPI.ingestChannelOrderPackage(
|
379
|
+
sellercraftStore,
|
380
|
+
newOrderPackage
|
381
|
+
)
|
382
|
+
} catch (e) {}
|
383
|
+
}
|
384
|
+
})
|
385
|
+
)
|
386
|
+
}
|
381
387
|
}
|
382
388
|
} catch (e) {}
|
383
389
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Ctx, Mutation, Resolver } from 'type-graphql'
|
1
|
+
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
2
2
|
import { getRepository } from 'typeorm'
|
3
3
|
|
4
4
|
import { config } from '@things-factory/env'
|
@@ -6,212 +6,215 @@ import { StoreAPI } from '@things-factory/integration-marketplace'
|
|
6
6
|
|
7
7
|
import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
|
8
8
|
import { MarketplaceChannel } from './marketplace-channel'
|
9
|
+
import { getShops } from '../../utils/tokencraft-util'
|
9
10
|
|
10
11
|
@Resolver()
|
11
12
|
export class MarketplaceChannelProductMutation {
|
12
13
|
@Mutation(returns => Boolean)
|
13
|
-
async syncAllMarketplaceChannelProducts(
|
14
|
+
async syncAllMarketplaceChannelProducts(
|
15
|
+
@Ctx() context: any,
|
16
|
+
@Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: string,
|
17
|
+
@Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string
|
18
|
+
): Promise<boolean> {
|
14
19
|
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
15
|
-
const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig
|
16
20
|
|
17
21
|
const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
|
18
22
|
|
19
23
|
for (var i = 0; i < channels.length; i++) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
for (var j = 0; j < shops.length; j++) {
|
36
|
-
var store = {
|
37
|
-
accessKey: shops[j]?.credential?.consumer_key || '',
|
38
|
-
accessSecret: shops[j]?.credential?.consumer_secret || '',
|
39
|
-
storeURL: shops[j]?.credential?.store_url || '',
|
40
|
-
platform: channels[i].name,
|
41
|
-
accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
|
42
|
-
channelShopId: shops[j]?.channel_shop_id
|
43
|
-
}
|
24
|
+
try {
|
25
|
+
let shops: any = await getShops(channels[i].channelId)
|
26
|
+
|
27
|
+
for (var j = 0; j < shops.length; j++) {
|
28
|
+
try {
|
29
|
+
var store = {
|
30
|
+
accessKey: shops[j]?.credential?.consumer_key || '',
|
31
|
+
accessSecret: shops[j]?.credential?.consumer_secret || '',
|
32
|
+
storeURL: shops[j]?.credential?.store_url || '',
|
33
|
+
platform: channels[i].name,
|
34
|
+
accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
|
35
|
+
channelShopId: shops[j]?.channel_shop_id,
|
36
|
+
storeId: shops[j]?.credential?.store_url || ''
|
37
|
+
}
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
39
|
+
let countryCode = shops[j].country_code
|
40
|
+
let channelCode = shops[j].org_prefix
|
41
|
+
let organisationId = shops[j].account_id
|
42
|
+
let channelShopId = shops[j].channel_shop_id
|
43
|
+
|
44
|
+
var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
|
45
|
+
|
46
|
+
const productResult = []
|
47
|
+
let totalPages: number = 1
|
48
|
+
let limit: number = 50
|
49
|
+
let parentLinks = []
|
50
|
+
|
51
|
+
for (let page = 0; page < totalPages; page++) {
|
52
|
+
const { results, total, parentLinkList } = await StoreAPI.getStoreProducts(store, {
|
53
|
+
pagination: { page, limit }
|
54
|
+
})
|
55
|
+
totalPages = Math.ceil(total / limit)
|
56
|
+
productResult.push(...results)
|
57
|
+
if (store.platform == 'magento') parentLinks.push(...parentLinkList)
|
58
|
+
}
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
const categoryResult = []
|
61
|
+
let totalPagesCategory: number = 1
|
62
|
+
let limitCategory: number = 100
|
69
63
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
if (store.platform != 'shopify') {
|
65
|
+
for (let page = 0; page < totalPagesCategory; page++) {
|
66
|
+
const { results, total } = await StoreAPI.getStoreProductCategories(store, {
|
67
|
+
pagination: { page, limitCategory }
|
68
|
+
})
|
69
|
+
totalPagesCategory = Math.ceil(total / limitCategory)
|
70
|
+
categoryResult.push(...results)
|
71
|
+
}
|
72
|
+
} else {
|
73
|
+
categoryResult.push({ id: 1, name: 'default', isActive: true })
|
74
|
+
}
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
qty: 1,
|
113
|
-
name: `${name} - ${variationSku}`,
|
114
|
-
sku: variationSku,
|
115
|
-
productVersions: [
|
76
|
+
let mappedProducts = productResult.map(item => {
|
77
|
+
let { categoryId, itemId: productId, name, brand, isVerified, images, sellercraftAttributes, variations } = item
|
78
|
+
|
79
|
+
variations = variations.map(variation => {
|
80
|
+
let {
|
81
|
+
variationSku,
|
82
|
+
variationId,
|
83
|
+
name,
|
84
|
+
isEnabled: isEnabled,
|
85
|
+
isSellable: isSellable,
|
86
|
+
sellercraftAttributes,
|
87
|
+
stockLocked,
|
88
|
+
qty: stockReported,
|
89
|
+
costPrice: fullPrice,
|
90
|
+
sellPrice: priceDiscounted,
|
91
|
+
length,
|
92
|
+
width,
|
93
|
+
height,
|
94
|
+
weight,
|
95
|
+
extraMetadata
|
96
|
+
} = variation
|
97
|
+
|
98
|
+
return {
|
99
|
+
variationSku,
|
100
|
+
variationId,
|
101
|
+
name,
|
102
|
+
isEnabled,
|
103
|
+
isSellable,
|
104
|
+
attributes: sellercraftAttributes || [],
|
105
|
+
stockLocked,
|
106
|
+
stockReported,
|
107
|
+
fullPrice: parseFloat(fullPrice) || 0,
|
108
|
+
priceDiscounted: parseFloat(priceDiscounted) || 0,
|
109
|
+
inventoryProducts: [
|
116
110
|
{
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
111
|
+
qty: 1,
|
112
|
+
name: `${name} - ${variationSku}`,
|
113
|
+
sku: variationSku,
|
114
|
+
productVersions: [
|
115
|
+
{
|
116
|
+
label: 'Default',
|
117
|
+
packageLengthMM: length,
|
118
|
+
packageWidthMM: width,
|
119
|
+
packageHeightMM: height,
|
120
|
+
packageWeightGram: weight,
|
121
|
+
qty: stockReported
|
122
|
+
}
|
123
|
+
]
|
123
124
|
}
|
124
|
-
]
|
125
|
+
],
|
126
|
+
extraMetadata
|
125
127
|
}
|
126
|
-
|
127
|
-
}
|
128
|
-
})
|
128
|
+
})
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
}
|
150
|
-
})
|
151
|
-
|
152
|
-
let mappedCategories = categoryResult.map(category => {
|
153
|
-
let { id: categoryId, name: categoryName, parent, isActive } = category
|
154
|
-
|
155
|
-
return {
|
156
|
-
categoryId,
|
157
|
-
categoryName,
|
158
|
-
parent,
|
159
|
-
isActive: isActive || true,
|
160
|
-
channelCode,
|
161
|
-
countryCode,
|
162
|
-
childrenCategories: []
|
163
|
-
}
|
164
|
-
})
|
165
|
-
|
166
|
-
if (store.platform == 'magento') {
|
167
|
-
let newList = []
|
168
|
-
for (let np of mappedProducts) {
|
169
|
-
if (np.productId == np.variations[0].variationId) {
|
170
|
-
let vars = mappedProducts
|
171
|
-
.filter(e => e.productId == np.productId)
|
172
|
-
.map(e => {
|
173
|
-
return e.variations[0]
|
174
|
-
})
|
175
|
-
np.variations = vars
|
176
|
-
if (np.variations.length > 1) {
|
177
|
-
np.variations = np.variations.filter(v => v.variationId != np.productId)
|
130
|
+
images = images?.map(image => {
|
131
|
+
return {
|
132
|
+
url: image
|
133
|
+
}
|
134
|
+
})
|
135
|
+
|
136
|
+
return {
|
137
|
+
organisationId,
|
138
|
+
channelShopId: channelShopId,
|
139
|
+
channelCode: channels[i].channelCode,
|
140
|
+
channelCountry: shops[j].country_code,
|
141
|
+
categoryId: store.platform == 'shopify' ? 1 : categoryId,
|
142
|
+
productId: parentLinks.find(e => e.children.includes(productId))?.id || productId,
|
143
|
+
name,
|
144
|
+
brand,
|
145
|
+
isVerified,
|
146
|
+
images,
|
147
|
+
attributes: sellercraftAttributes || [],
|
148
|
+
variations
|
178
149
|
}
|
179
|
-
|
180
|
-
}
|
181
|
-
}
|
182
|
-
mappedProducts = newList
|
183
|
-
}
|
150
|
+
})
|
184
151
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
152
|
+
let mappedCategories = categoryResult.map(category => {
|
153
|
+
let { id: categoryId, name: categoryName, parent, isActive } = category
|
154
|
+
|
155
|
+
return {
|
156
|
+
categoryId,
|
157
|
+
categoryName,
|
158
|
+
parent,
|
159
|
+
isActive: isActive || true,
|
160
|
+
channelCode,
|
161
|
+
countryCode,
|
162
|
+
childrenCategories: []
|
163
|
+
}
|
164
|
+
})
|
194
165
|
|
195
|
-
|
196
|
-
|
197
|
-
|
166
|
+
if (store.platform == 'magento') {
|
167
|
+
let newList = []
|
168
|
+
for (let np of mappedProducts) {
|
169
|
+
if (np.productId == np.variations[0].variationId) {
|
170
|
+
let vars = mappedProducts
|
171
|
+
.filter(e => e.productId == np.productId)
|
172
|
+
.map(e => {
|
173
|
+
return e.variations[0]
|
174
|
+
})
|
175
|
+
np.variations = vars
|
176
|
+
if (np.variations.length > 1) {
|
177
|
+
np.variations = np.variations.filter(v => v.variationId != np.productId)
|
178
|
+
}
|
179
|
+
newList.push(np)
|
180
|
+
}
|
181
|
+
}
|
182
|
+
mappedProducts = newList
|
198
183
|
}
|
199
|
-
}).filter(e => e)
|
200
184
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
185
|
+
try {
|
186
|
+
let filterList = []
|
187
|
+
mappedCategories = mappedCategories.map(category => {
|
188
|
+
if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
|
189
|
+
category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
|
190
|
+
filterList.push(...mappedCategories.filter(e => e.parent == category.categoryId))
|
191
|
+
}
|
192
|
+
return category
|
193
|
+
})
|
194
|
+
|
195
|
+
mappedCategories = mappedCategories
|
196
|
+
.map(mc => {
|
197
|
+
if (filterList.indexOf(mc) == -1) {
|
198
|
+
return mc
|
199
|
+
}
|
200
|
+
})
|
201
|
+
.filter(e => e)
|
205
202
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
})
|
211
|
-
}
|
212
|
-
} catch (e) {}
|
213
|
-
}
|
203
|
+
await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
|
204
|
+
categories: mappedCategories
|
205
|
+
})
|
206
|
+
} catch (e) {}
|
214
207
|
|
208
|
+
try {
|
209
|
+
for (let k = 0, l = mappedProducts.length; k < l; k++) {
|
210
|
+
await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
|
211
|
+
products: [mappedProducts[k]]
|
212
|
+
})
|
213
|
+
}
|
214
|
+
} catch (e) {}
|
215
|
+
} catch (e) {}
|
216
|
+
}
|
217
|
+
} catch (e) {}
|
215
218
|
}
|
216
219
|
return true
|
217
220
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
2
2
|
import { In } from 'typeorm'
|
3
|
-
import
|
3
|
+
import { v4 as uuidv4 } from 'uuid'
|
4
4
|
|
5
5
|
import { Sellercraft, SellercraftPlatform, SellercraftStatus } from './sellercraft'
|
6
6
|
import { NewSellercraft, SellercraftPatch } from './sellercraft-type'
|
@@ -14,7 +14,7 @@ export class SellercraftMutation {
|
|
14
14
|
|
15
15
|
return await tx.getRepository(Sellercraft).save({
|
16
16
|
...sellercraft,
|
17
|
-
name:
|
17
|
+
name: uuidv4(),
|
18
18
|
domain,
|
19
19
|
creator: user,
|
20
20
|
updater: user
|
@@ -60,7 +60,7 @@ export class SellercraftMutation {
|
|
60
60
|
const result = await sellercraftRepo.save({
|
61
61
|
...newRecord,
|
62
62
|
domain,
|
63
|
-
name:
|
63
|
+
name: uuidv4(),
|
64
64
|
status: SellercraftStatus.ACTIVE,
|
65
65
|
platform: SellercraftPlatform.SELLERCRAFT,
|
66
66
|
creator: user,
|
@@ -18,7 +18,7 @@ export class SellercraftQuery {
|
|
18
18
|
async sellercrafts(@Args() params: ListParam, @Ctx() context: any): Promise<SellercraftList> {
|
19
19
|
const { domain } = context.state
|
20
20
|
|
21
|
-
const convertedParams = convertListParams(params, domain
|
21
|
+
const convertedParams = convertListParams(params, { domain })
|
22
22
|
const [items, total] = await getRepository(Sellercraft).findAndCount(convertedParams)
|
23
23
|
|
24
24
|
return { items, total }
|