@things-factory/integration-sellercraft 5.0.14 → 6.0.0-alpha.3
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/controllers/sellercraft/sellercraft.js +6 -6
- package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/decorators.js +12 -6
- package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/index.js +2 -2
- package/dist-server/controllers/sellercraft-api/index.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +5 -3
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration-api/index.js +2 -2
- package/dist-server/controllers/sellercraft-channel-integration-api/index.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +29 -3
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +294 -258
- 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 +59 -16
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel.js +8 -4
- package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-mutation.js +6 -4
- package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js +6 -8
- package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft.js +8 -4
- package/dist-server/service/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/server/controllers/sellercraft/sellercraft.ts +6 -6
- package/server/controllers/sellercraft-api/decorators.ts +11 -6
- package/server/controllers/sellercraft-api/index.ts +1 -1
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +5 -3
- package/server/controllers/sellercraft-channel-integration-api/index.ts +1 -1
- package/server/routers/sellercraft-router.ts +45 -4
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +348 -310
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +78 -17
- package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
- package/server/service/sellercraft/sellercraft-mutation.ts +17 -9
- package/server/service/sellercraft/sellercraft-query.ts +7 -8
- package/server/service/sellercraft/sellercraft.ts +5 -1
@@ -1,29 +1,42 @@
|
|
1
1
|
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
2
|
-
import { getRepository } from 'typeorm'
|
3
2
|
|
4
3
|
import { config } from '@things-factory/env'
|
5
4
|
import { StoreAPI } from '@things-factory/integration-marketplace'
|
5
|
+
import { getRepository } from '@things-factory/shell'
|
6
6
|
|
7
7
|
import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
|
8
|
-
import { MarketplaceChannel } from './marketplace-channel'
|
9
8
|
import { getShops } from '../../utils/tokencraft-util'
|
9
|
+
import { MarketplaceChannel } from './marketplace-channel'
|
10
10
|
|
11
11
|
@Resolver()
|
12
12
|
export class MarketplaceChannelProductMutation {
|
13
13
|
@Mutation(returns => Boolean)
|
14
14
|
async syncAllMarketplaceChannelProducts(
|
15
|
-
@Ctx() context:
|
15
|
+
@Ctx() context: ResolverContext,
|
16
16
|
@Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: string,
|
17
|
-
@Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string
|
17
|
+
@Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string,
|
18
|
+
@Arg('productBatchSize', { nullable: true }) productBatchSize?: string,
|
19
|
+
@Arg('channelId', { nullable: true }) channelId?: string,
|
20
|
+
@Arg('shopId', { nullable: true }) shopId?: string,
|
21
|
+
@Arg('airflow', { nullable: true }) airflow?: boolean
|
18
22
|
): Promise<boolean> {
|
19
23
|
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
20
24
|
|
21
|
-
|
25
|
+
let channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
|
26
|
+
let errors: any = []
|
27
|
+
|
28
|
+
if (channelId) {
|
29
|
+
channels = channels.filter(channel => channel.channelId == channelId)
|
30
|
+
}
|
22
31
|
|
23
32
|
for (var i = 0; i < channels.length; i++) {
|
24
33
|
try {
|
25
34
|
let shops: any = await getShops(channels[i].channelId)
|
26
35
|
|
36
|
+
if (shopId) {
|
37
|
+
shops = shops.filter(shop => shop.channel_shop_id == shopId)
|
38
|
+
}
|
39
|
+
|
27
40
|
for (var j = 0; j < shops.length; j++) {
|
28
41
|
try {
|
29
42
|
var store = {
|
@@ -47,14 +60,24 @@ export class MarketplaceChannelProductMutation {
|
|
47
60
|
let totalPages: number = 1
|
48
61
|
let limit: number = 50
|
49
62
|
let parentLinks = []
|
63
|
+
let cursor: string
|
50
64
|
|
51
65
|
for (let page = 0; page < totalPages; page++) {
|
52
|
-
const {
|
53
|
-
|
66
|
+
const {
|
67
|
+
results,
|
68
|
+
total,
|
69
|
+
parentLinkList,
|
70
|
+
page_info: nextCursor
|
71
|
+
} = await StoreAPI.getStoreProducts(store, {
|
72
|
+
pagination: { page, limit },
|
73
|
+
pageInfo: cursor,
|
74
|
+
fromUpdatedDate,
|
75
|
+
toUpdatedDate
|
54
76
|
})
|
55
77
|
totalPages = Math.ceil(total / limit)
|
56
78
|
productResult.push(...results)
|
57
79
|
if (store.platform == 'magento') parentLinks.push(...parentLinkList)
|
80
|
+
cursor = nextCursor
|
58
81
|
}
|
59
82
|
|
60
83
|
const categoryResult = []
|
@@ -74,7 +97,16 @@ export class MarketplaceChannelProductMutation {
|
|
74
97
|
}
|
75
98
|
|
76
99
|
let mappedProducts = productResult.map(item => {
|
77
|
-
let {
|
100
|
+
let {
|
101
|
+
categoryId,
|
102
|
+
itemId: productId,
|
103
|
+
name,
|
104
|
+
brand,
|
105
|
+
isVerified,
|
106
|
+
images,
|
107
|
+
sellercraftAttributes,
|
108
|
+
variations
|
109
|
+
} = item
|
78
110
|
|
79
111
|
variations = variations.map(variation => {
|
80
112
|
let {
|
@@ -203,18 +235,47 @@ export class MarketplaceChannelProductMutation {
|
|
203
235
|
await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
|
204
236
|
categories: mappedCategories
|
205
237
|
})
|
206
|
-
} catch (e) {
|
238
|
+
} catch (e) {
|
239
|
+
errors.push({
|
240
|
+
name: 'Category Ingestion Error',
|
241
|
+
msg: JSON.stringify(e) || {}
|
242
|
+
})
|
243
|
+
}
|
207
244
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
245
|
+
let bs = parseInt(productBatchSize) || mappedProducts.length
|
246
|
+
|
247
|
+
if (mappedProducts.length > 0) {
|
248
|
+
while (mappedProducts.length > 0) {
|
249
|
+
let spliceResult = mappedProducts.splice(0, mappedProducts.length >= bs ? bs : mappedProducts.length)
|
250
|
+
|
251
|
+
try {
|
252
|
+
await SellercraftChannelIntegrationAPI.ingestChannelProduct(sellercraftStore, {
|
253
|
+
products: spliceResult
|
254
|
+
})
|
255
|
+
} catch (e) {
|
256
|
+
errors.push({
|
257
|
+
name: 'Product Ingestion Error',
|
258
|
+
msg: JSON.stringify(e) || {}
|
259
|
+
})
|
260
|
+
}
|
213
261
|
}
|
214
|
-
}
|
215
|
-
} catch (e) {
|
262
|
+
}
|
263
|
+
} catch (e) {
|
264
|
+
errors.push({
|
265
|
+
name: 'Product Processing / Mapping Error',
|
266
|
+
msg: JSON.stringify(e) || {}
|
267
|
+
})
|
268
|
+
}
|
216
269
|
}
|
217
|
-
} catch (e) {
|
270
|
+
} catch (e) {
|
271
|
+
errors.push({
|
272
|
+
name: 'Store Error',
|
273
|
+
msg: JSON.stringify(e) || {}
|
274
|
+
})
|
275
|
+
}
|
276
|
+
}
|
277
|
+
if (errors.length > 1 && airflow) {
|
278
|
+
throw errors
|
218
279
|
}
|
219
280
|
return true
|
220
281
|
}
|
@@ -9,7 +9,10 @@ import { NewSellercraft, SellercraftPatch } from './sellercraft-type'
|
|
9
9
|
export class SellercraftMutation {
|
10
10
|
@Directive('@transaction')
|
11
11
|
@Mutation(returns => Sellercraft, { description: 'To create new Sellercraft' })
|
12
|
-
async createSellercraft(
|
12
|
+
async createSellercraft(
|
13
|
+
@Arg('sellercraft') sellercraft: NewSellercraft,
|
14
|
+
@Ctx() context: ResolverContext
|
15
|
+
): Promise<Sellercraft> {
|
13
16
|
const { domain, user, tx } = context.state
|
14
17
|
|
15
18
|
return await tx.getRepository(Sellercraft).save({
|
@@ -26,12 +29,12 @@ export class SellercraftMutation {
|
|
26
29
|
async updateSellercraft(
|
27
30
|
@Arg('id') id: string,
|
28
31
|
@Arg('patch') patch: SellercraftPatch,
|
29
|
-
@Ctx() context:
|
32
|
+
@Ctx() context: ResolverContext
|
30
33
|
): Promise<Sellercraft> {
|
31
34
|
const { user, tx } = context.state
|
32
35
|
|
33
36
|
const repository = tx.getRepository(Sellercraft)
|
34
|
-
const sellercraft = await repository.
|
37
|
+
const sellercraft = await repository.findOneBy({ id })
|
35
38
|
|
36
39
|
return await repository.save({
|
37
40
|
...sellercraft,
|
@@ -44,7 +47,7 @@ export class SellercraftMutation {
|
|
44
47
|
@Mutation(returns => [Sellercraft], { description: "To modify multiple Sellercrafts' information" })
|
45
48
|
async updateMultipleSellercraft(
|
46
49
|
@Arg('patches', type => [SellercraftPatch]) patches: SellercraftPatch[],
|
47
|
-
@Ctx() context:
|
50
|
+
@Ctx() context: ResolverContext
|
48
51
|
): Promise<Sellercraft[]> {
|
49
52
|
const { domain, user, tx } = context.state
|
50
53
|
|
@@ -74,7 +77,7 @@ export class SellercraftMutation {
|
|
74
77
|
if (_updateRecords.length > 0) {
|
75
78
|
for (let i = 0; i < _updateRecords.length; i++) {
|
76
79
|
const newRecord = _updateRecords[i]
|
77
|
-
const sellercraft = await sellercraftRepo.
|
80
|
+
const sellercraft = await sellercraftRepo.findOneBy({ id: newRecord.id })
|
78
81
|
|
79
82
|
const result = await sellercraftRepo.save({
|
80
83
|
...sellercraft,
|
@@ -91,18 +94,23 @@ export class SellercraftMutation {
|
|
91
94
|
|
92
95
|
@Directive('@transaction')
|
93
96
|
@Mutation(returns => Boolean, { description: 'To delete Sellercraft' })
|
94
|
-
async deleteSellercraft(@Arg('id') id: string, @Ctx() context:
|
97
|
+
async deleteSellercraft(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
95
98
|
const { domain, tx } = context.state
|
96
99
|
|
97
|
-
await tx.getRepository(Sellercraft).delete({ domain, id })
|
100
|
+
await tx.getRepository(Sellercraft).delete({ domain: { id: domain.id }, id })
|
98
101
|
return true
|
99
102
|
}
|
100
103
|
|
101
104
|
@Directive('@transaction')
|
102
105
|
@Mutation(returns => Boolean, { description: 'To delete multiple sellercrafts' })
|
103
|
-
async deleteSellercrafts(
|
106
|
+
async deleteSellercrafts(
|
107
|
+
@Arg('ids', type => [String]) ids: string[],
|
108
|
+
@Ctx() context: ResolverContext
|
109
|
+
): Promise<boolean> {
|
104
110
|
const { domain, tx, user } = context.state
|
105
|
-
let sellercrafts: Sellercraft[] = await tx
|
111
|
+
let sellercrafts: Sellercraft[] = await tx
|
112
|
+
.getRepository(Sellercraft)
|
113
|
+
.find({ where: { domain: { id: domain.id }, id: In(ids) } })
|
106
114
|
|
107
115
|
sellercrafts = sellercrafts.map((sellercraft: Sellercraft) => {
|
108
116
|
return {
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
2
|
-
import { getRepository } from 'typeorm'
|
3
2
|
|
4
3
|
import { User } from '@things-factory/auth-base'
|
5
|
-
import { convertListParams, Domain, ListParam } from '@things-factory/shell'
|
4
|
+
import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
6
5
|
|
7
6
|
import { Sellercraft } from './sellercraft'
|
8
7
|
import { SellercraftList } from './sellercraft-type'
|
@@ -10,12 +9,12 @@ import { SellercraftList } from './sellercraft-type'
|
|
10
9
|
@Resolver(Sellercraft)
|
11
10
|
export class SellercraftQuery {
|
12
11
|
@Query(returns => Sellercraft, { description: 'To fetch a Sellercraft' })
|
13
|
-
async sellercraft(@Arg('id') id: string, @Ctx() context:
|
14
|
-
return await getRepository(Sellercraft).
|
12
|
+
async sellercraft(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Sellercraft> {
|
13
|
+
return await getRepository(Sellercraft).findOneBy({ id })
|
15
14
|
}
|
16
15
|
|
17
16
|
@Query(returns => SellercraftList, { description: 'To fetch multiple Sellercrafts' })
|
18
|
-
async sellercrafts(@Args() params: ListParam, @Ctx() context:
|
17
|
+
async sellercrafts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<SellercraftList> {
|
19
18
|
const { domain } = context.state
|
20
19
|
|
21
20
|
const convertedParams = convertListParams(params, { domain })
|
@@ -26,16 +25,16 @@ export class SellercraftQuery {
|
|
26
25
|
|
27
26
|
@FieldResolver(type => Domain)
|
28
27
|
async domain(@Root() sellercraft: Sellercraft): Promise<Domain> {
|
29
|
-
return await getRepository(Domain).
|
28
|
+
return await getRepository(Domain).findOneBy({ id: sellercraft.domainId })
|
30
29
|
}
|
31
30
|
|
32
31
|
@FieldResolver(type => User)
|
33
32
|
async updater(@Root() sellercraft: Sellercraft): Promise<User> {
|
34
|
-
return await getRepository(User).
|
33
|
+
return await getRepository(User).findOneBy({ id: sellercraft.updaterId })
|
35
34
|
}
|
36
35
|
|
37
36
|
@FieldResolver(type => User)
|
38
37
|
async creator(@Root() sellercraft: Sellercraft): Promise<User> {
|
39
|
-
return await getRepository(User).
|
38
|
+
return await getRepository(User).findOneBy({ id: sellercraft.creatorId })
|
40
39
|
}
|
41
40
|
}
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
} from 'typeorm'
|
12
12
|
|
13
13
|
import { User } from '@things-factory/auth-base'
|
14
|
-
import { Domain } from '@things-factory/shell'
|
14
|
+
import { Domain, ScalarObject } from '@things-factory/shell'
|
15
15
|
|
16
16
|
export enum SellercraftStatus {
|
17
17
|
ACTIVE = 'ACTIVE',
|
@@ -68,6 +68,10 @@ export class Sellercraft {
|
|
68
68
|
@Field({ nullable: true })
|
69
69
|
status?: SellercraftStatus
|
70
70
|
|
71
|
+
@Column('simple-json', { nullable: true })
|
72
|
+
@Field(type => ScalarObject, { nullable: true })
|
73
|
+
sellercraftSetting?: object
|
74
|
+
|
71
75
|
@CreateDateColumn()
|
72
76
|
@Field({ nullable: true })
|
73
77
|
createdAt?: Date
|