@things-factory/integration-sellercraft 5.0.0-alpha.38 → 5.0.0-alpha.39

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 (34) hide show
  1. package/dist-server/constants/order-status-mapping.js +21 -3
  2. package/dist-server/constants/order-status-mapping.js.map +1 -1
  3. package/dist-server/constants/platform.js +3 -1
  4. package/dist-server/constants/platform.js.map +1 -1
  5. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js +3 -2
  6. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.js.map +1 -1
  7. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js +5 -2
  8. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.js.map +1 -1
  9. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +21 -14
  10. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
  11. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js +15 -11
  12. package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.js.map +1 -1
  13. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js +8 -4
  14. package/dist-server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.js.map +1 -1
  15. package/dist-server/routers/sellercraft-router.js +195 -75
  16. package/dist-server/routers/sellercraft-router.js.map +1 -1
  17. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +317 -103
  18. package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
  19. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +83 -25
  20. package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
  21. package/dist-server/service/marketplace-channel/marketplace-channel.js +5 -0
  22. package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
  23. package/package.json +15 -15
  24. package/server/constants/order-status-mapping.ts +21 -2
  25. package/server/constants/platform.ts +3 -1
  26. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +4 -3
  27. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +6 -2
  28. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +22 -15
  29. package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +26 -21
  30. package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +8 -4
  31. package/server/routers/sellercraft-router.ts +199 -79
  32. package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +379 -149
  33. package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +83 -26
  34. package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
@@ -1,11 +1,11 @@
1
1
  import { 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 MarketplaceChannelProductMutation {
@@ -14,7 +14,7 @@ export class MarketplaceChannelProductMutation {
14
14
  const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
15
15
  const { tokenCraftApiKey: apiKey, getShopsTokenCraftUrl } = sellercraftChannelIntegrationConfig
16
16
 
17
- const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find()
17
+ const channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
18
18
 
19
19
  for (var i = 0; i < channels.length; i++) {
20
20
  var channelsFullPath = getShopsTokenCraftUrl + '?channel_id=' + channels[i].channelId
@@ -34,11 +34,12 @@ export class MarketplaceChannelProductMutation {
34
34
 
35
35
  for (var j = 0; j < shops.length; j++) {
36
36
  var store = {
37
- accessKey: shops[j].credential.consumer_key,
38
- accessSecret: shops[j].credential.consumer_secret,
39
- storeURL: shops[j].credential.store_url,
37
+ accessKey: shops[j]?.credential?.consumer_key || '',
38
+ accessSecret: shops[j]?.credential?.consumer_secret || '',
39
+ storeURL: shops[j]?.credential?.store_url || '',
40
40
  platform: channels[i].name,
41
- accessToken: shops[j].credential.access_token // Magento+
41
+ accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
42
+ channelShopId: shops[j]?.channel_shop_id
42
43
  }
43
44
 
44
45
  let countryCode = shops[j].country_code
@@ -48,11 +49,33 @@ export class MarketplaceChannelProductMutation {
48
49
 
49
50
  var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
50
51
 
51
- const productResult = await StoreAPI.getStoreProducts(store, {})
52
+ const productResult = []
53
+ let totalPages: number = 1
54
+ let limit: number = 50
55
+ let parentLinks = []
52
56
 
53
- const categoryResult = await StoreAPI.getStoreProductCategories(store, {})
57
+ for (let page = 0; page < totalPages; page++) {
58
+ const { results, total, parentLinkList } = await StoreAPI.getStoreProducts(store, {
59
+ pagination: { page, limit }
60
+ })
61
+ totalPages = Math.ceil(total / limit)
62
+ productResult.push(...results)
63
+ if (store.platform == 'magento') parentLinks.push(...parentLinkList)
64
+ }
54
65
 
55
- let mappedProducts = productResult.results.map(item => {
66
+ const categoryResult = []
67
+ let totalPagesCategory: number = 1
68
+ let limitCategory: number = 100
69
+
70
+ for (let page = 0; page < totalPagesCategory; page++) {
71
+ const { results, total } = await StoreAPI.getStoreProductCategories(store, {
72
+ pagination: { page, limitCategory }
73
+ })
74
+ totalPagesCategory = Math.ceil(total / limitCategory)
75
+ categoryResult.push(...results)
76
+ }
77
+
78
+ let mappedProducts = productResult.map(item => {
56
79
  let { categoryId, itemId: productId, name, brand, isVerified, images, attributes, variations } = item
57
80
 
58
81
  variations = variations.map(variation => {
@@ -61,7 +84,7 @@ export class MarketplaceChannelProductMutation {
61
84
  variationId,
62
85
  name,
63
86
  isEnabled: isEnabled,
64
- isEnabled: isSellable,
87
+ isSellable: isSellable,
65
88
  attributes,
66
89
  stockLocked,
67
90
  qty: stockReported,
@@ -86,7 +109,7 @@ export class MarketplaceChannelProductMutation {
86
109
  priceDiscounted,
87
110
  inventoryProducts: [
88
111
  {
89
- qty: stockReported,
112
+ qty: 1,
90
113
  name: `${name} - ${variationSku}`,
91
114
  sku: variationSku,
92
115
  productVersions: [
@@ -96,7 +119,7 @@ export class MarketplaceChannelProductMutation {
96
119
  packageWidthMM: width,
97
120
  packageHeightMM: height,
98
121
  packageWeightGram: weight,
99
- qty: 1
122
+ qty: stockReported
100
123
  }
101
124
  ]
102
125
  }
@@ -116,7 +139,7 @@ export class MarketplaceChannelProductMutation {
116
139
  channelCode: channels[i].channelCode,
117
140
  channelCountry: shops[j].country_code,
118
141
  categoryId,
119
- productId,
142
+ productId: parentLinks.find(e => e.children.includes(productId))?.id || productId,
120
143
  name,
121
144
  brand,
122
145
  isVerified,
@@ -126,14 +149,13 @@ export class MarketplaceChannelProductMutation {
126
149
  }
127
150
  })
128
151
 
129
- let mappedCategories = categoryResult.results.map(category => {
152
+ let mappedCategories = categoryResult.map(category => {
130
153
  let { id: categoryId, name: categoryName, parent, isActive } = category
131
154
 
132
155
  return {
133
156
  categoryId,
134
157
  categoryName,
135
158
  parent,
136
- isLeaf: parent == 0 ? false : true,
137
159
  isActive: isActive || true,
138
160
  channelCode,
139
161
  countryCode,
@@ -141,21 +163,56 @@ export class MarketplaceChannelProductMutation {
141
163
  }
142
164
  })
143
165
 
144
- mappedCategories = mappedCategories.map(category => {
145
- if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
146
- category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
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
+ }
147
181
  }
148
- return category
149
- })
182
+ mappedProducts = newList
183
+ }
150
184
 
151
- await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
152
- categories: mappedCategories
153
- })
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
+ })
154
194
 
155
- await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, { products: mappedProducts })
195
+ mappedCategories = mappedCategories.map(mc => {
196
+ if (filterList.indexOf(mc) == -1) {
197
+ return mc
198
+ }
199
+ }).filter(e => e)
200
+
201
+ await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
202
+ categories: mappedCategories
203
+ })
204
+ } catch (e) {}
205
+
206
+ try {
207
+ for (let k = 0, l = mappedProducts.length; k < l; k++) {
208
+ await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
209
+ products: [mappedProducts[k]]
210
+ })
211
+ }
212
+ } catch (e) {}
156
213
  }
157
214
 
158
- return true
159
215
  }
216
+ return true
160
217
  }
161
218
  }
@@ -40,6 +40,10 @@ export class MarketplaceChannel {
40
40
  @Field()
41
41
  channelId: string
42
42
 
43
+ @Column({ default: true })
44
+ @Field()
45
+ isActive: boolean
46
+
43
47
  @CreateDateColumn()
44
48
  @Field({ nullable: true })
45
49
  createdAt?: Date