@things-factory/integration-sellercraft 8.0.0-beta.0 → 8.0.0-beta.2
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +13 -13
- package/server/constants/index.ts +0 -2
- package/server/constants/order-status-mapping.ts +0 -28
- package/server/constants/platform.ts +0 -6
- package/server/controllers/index.ts +0 -5
- package/server/controllers/sellercraft/apis/add-inbound-order.ts +0 -50
- package/server/controllers/sellercraft/apis/echo.ts +0 -14
- package/server/controllers/sellercraft/apis/fetch-order-document.ts +0 -18
- package/server/controllers/sellercraft/apis/index.ts +0 -8
- package/server/controllers/sellercraft/apis/initiate-order-document.ts +0 -17
- package/server/controllers/sellercraft/apis/initiate-order-shipment.ts +0 -29
- package/server/controllers/sellercraft/apis/pack-marketplace-order.ts +0 -35
- package/server/controllers/sellercraft/apis/update-marketplace-order.ts +0 -14
- package/server/controllers/sellercraft/apis/update-product.ts +0 -21
- package/server/controllers/sellercraft/index.ts +0 -7
- package/server/controllers/sellercraft/platform-action.ts +0 -39
- package/server/controllers/sellercraft/sellercraft.ts +0 -109
- package/server/controllers/sellercraft-api/decorators.ts +0 -52
- package/server/controllers/sellercraft-api/index.ts +0 -51
- package/server/controllers/sellercraft-api/types.ts +0 -0
- package/server/controllers/sellercraft-channel-integration/apis/echo.ts +0 -14
- package/server/controllers/sellercraft-channel-integration/apis/index.ts +0 -6
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-categories.ts +0 -37
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-category-attributes.ts +0 -65
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order-package.ts +0 -62
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +0 -92
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-product.ts +0 -97
- package/server/controllers/sellercraft-channel-integration/index.ts +0 -7
- package/server/controllers/sellercraft-channel-integration/platform-action.ts +0 -39
- package/server/controllers/sellercraft-channel-integration/sellercraft-channel-integration.ts +0 -115
- package/server/controllers/sellercraft-channel-integration-api/decorators.ts +0 -45
- package/server/controllers/sellercraft-channel-integration-api/index.ts +0 -45
- package/server/controllers/sellercraft-channel-integration-api/types.ts +0 -0
- package/server/index.ts +0 -7
- package/server/middlewares/index.ts +0 -3
- package/server/migrations/index.ts +0 -9
- package/server/routers/sellercraft-router.ts +0 -326
- package/server/routes.ts +0 -32
- package/server/service/index.ts +0 -23
- package/server/service/marketplace-channel/index.ts +0 -6
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +0 -456
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +0 -282
- package/server/service/marketplace-channel/marketplace-channel.ts +0 -76
- package/server/service/sellercraft/index.ts +0 -6
- package/server/service/sellercraft/sellercraft-mutation.ts +0 -126
- package/server/service/sellercraft/sellercraft-query.ts +0 -43
- package/server/service/sellercraft/sellercraft-type.ts +0 -54
- package/server/service/sellercraft/sellercraft.ts +0 -96
- package/server/utils/tokencraft-util.ts +0 -60
- package/tsconfig.json +0 -9
@@ -1,282 +0,0 @@
|
|
1
|
-
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
2
|
-
|
3
|
-
import { config } from '@things-factory/env'
|
4
|
-
import { StoreAPI } from '@things-factory/integration-marketplace'
|
5
|
-
import { getRepository } from '@things-factory/shell'
|
6
|
-
|
7
|
-
import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
|
8
|
-
import { getShops } from '../../utils/tokencraft-util'
|
9
|
-
import { MarketplaceChannel } from './marketplace-channel'
|
10
|
-
|
11
|
-
@Resolver()
|
12
|
-
export class MarketplaceChannelProductMutation {
|
13
|
-
@Mutation(returns => Boolean)
|
14
|
-
async syncAllMarketplaceChannelProducts(
|
15
|
-
@Ctx() context: ResolverContext,
|
16
|
-
@Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: 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
|
22
|
-
): Promise<boolean> {
|
23
|
-
const sellercraftChannelIntegrationConfig = config.get('sellercraftChannelIntegrationConfig', {})
|
24
|
-
|
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
|
-
}
|
31
|
-
|
32
|
-
for (var i = 0; i < channels.length; i++) {
|
33
|
-
try {
|
34
|
-
let shops: any = await getShops(channels[i].channelId)
|
35
|
-
|
36
|
-
if (shopId) {
|
37
|
-
shops = shops.filter(shop => shop.channel_shop_id == shopId)
|
38
|
-
}
|
39
|
-
|
40
|
-
for (var j = 0; j < shops.length; j++) {
|
41
|
-
try {
|
42
|
-
var store = {
|
43
|
-
accessKey: shops[j]?.credential?.consumer_key || '',
|
44
|
-
accessSecret: shops[j]?.credential?.consumer_secret || '',
|
45
|
-
storeURL: shops[j]?.credential?.store_url || '',
|
46
|
-
platform: channels[i].name,
|
47
|
-
accessToken: shops[j]?.credential?.access_token, // Magento+, Tiktok
|
48
|
-
channelShopId: shops[j]?.channel_shop_id,
|
49
|
-
storeId: shops[j]?.credential?.store_url || ''
|
50
|
-
}
|
51
|
-
|
52
|
-
let countryCode = shops[j].country_code
|
53
|
-
let channelCode = shops[j].org_prefix
|
54
|
-
let organisationId = shops[j].account_id
|
55
|
-
let channelShopId = shops[j].channel_shop_id
|
56
|
-
|
57
|
-
var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
|
58
|
-
|
59
|
-
const productResult = []
|
60
|
-
let totalPages: number = 1
|
61
|
-
let limit: number = 50
|
62
|
-
let parentLinks = []
|
63
|
-
let cursor: string
|
64
|
-
|
65
|
-
for (let page = 0; page < totalPages; page++) {
|
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
|
76
|
-
})
|
77
|
-
totalPages = Math.ceil(total / limit)
|
78
|
-
productResult.push(...results)
|
79
|
-
if (store.platform == 'magento') parentLinks.push(...parentLinkList)
|
80
|
-
cursor = nextCursor
|
81
|
-
}
|
82
|
-
|
83
|
-
const categoryResult = []
|
84
|
-
let totalPagesCategory: number = 1
|
85
|
-
let limitCategory: number = 100
|
86
|
-
|
87
|
-
if (store.platform != 'shopify') {
|
88
|
-
for (let page = 0; page < totalPagesCategory; page++) {
|
89
|
-
const { results, total } = await StoreAPI.getStoreProductCategories(store, {
|
90
|
-
pagination: { page, limitCategory }
|
91
|
-
})
|
92
|
-
totalPagesCategory = Math.ceil(total / limitCategory)
|
93
|
-
categoryResult.push(...results)
|
94
|
-
}
|
95
|
-
} else {
|
96
|
-
categoryResult.push({ id: 1, name: 'default', isActive: true })
|
97
|
-
}
|
98
|
-
|
99
|
-
let mappedProducts = productResult.map(item => {
|
100
|
-
let {
|
101
|
-
categoryId,
|
102
|
-
itemId: productId,
|
103
|
-
name,
|
104
|
-
brand,
|
105
|
-
isVerified,
|
106
|
-
images,
|
107
|
-
sellercraftAttributes,
|
108
|
-
variations
|
109
|
-
} = item
|
110
|
-
|
111
|
-
variations = variations.map(variation => {
|
112
|
-
let {
|
113
|
-
variationSku,
|
114
|
-
variationId,
|
115
|
-
name,
|
116
|
-
isEnabled: isEnabled,
|
117
|
-
isSellable: isSellable,
|
118
|
-
sellercraftAttributes,
|
119
|
-
stockLocked,
|
120
|
-
qty: stockReported,
|
121
|
-
costPrice: fullPrice,
|
122
|
-
sellPrice: priceDiscounted,
|
123
|
-
length,
|
124
|
-
width,
|
125
|
-
height,
|
126
|
-
weight,
|
127
|
-
extraMetadata
|
128
|
-
} = variation
|
129
|
-
|
130
|
-
return {
|
131
|
-
variationSku,
|
132
|
-
variationId,
|
133
|
-
name,
|
134
|
-
isEnabled,
|
135
|
-
isSellable,
|
136
|
-
attributes: sellercraftAttributes || [],
|
137
|
-
stockLocked,
|
138
|
-
stockReported,
|
139
|
-
fullPrice: parseFloat(fullPrice) || 0,
|
140
|
-
priceDiscounted: parseFloat(priceDiscounted) || 0,
|
141
|
-
inventoryProducts: [
|
142
|
-
{
|
143
|
-
qty: 1,
|
144
|
-
name: `${name} - ${variationSku}`,
|
145
|
-
sku: variationSku,
|
146
|
-
productVersions: [
|
147
|
-
{
|
148
|
-
label: 'Default',
|
149
|
-
packageLengthMM: length,
|
150
|
-
packageWidthMM: width,
|
151
|
-
packageHeightMM: height,
|
152
|
-
packageWeightGram: weight,
|
153
|
-
qty: stockReported
|
154
|
-
}
|
155
|
-
]
|
156
|
-
}
|
157
|
-
],
|
158
|
-
extraMetadata
|
159
|
-
}
|
160
|
-
})
|
161
|
-
|
162
|
-
images = images?.map(image => {
|
163
|
-
return {
|
164
|
-
url: image
|
165
|
-
}
|
166
|
-
})
|
167
|
-
|
168
|
-
return {
|
169
|
-
organisationId,
|
170
|
-
channelShopId: channelShopId,
|
171
|
-
channelCode: channels[i].channelCode,
|
172
|
-
channelCountry: shops[j].country_code,
|
173
|
-
categoryId: store.platform == 'shopify' ? 1 : categoryId,
|
174
|
-
productId: parentLinks.find(e => e.children.includes(productId))?.id || productId,
|
175
|
-
name,
|
176
|
-
brand,
|
177
|
-
isVerified,
|
178
|
-
images,
|
179
|
-
attributes: sellercraftAttributes || [],
|
180
|
-
variations
|
181
|
-
}
|
182
|
-
})
|
183
|
-
|
184
|
-
let mappedCategories = categoryResult.map(category => {
|
185
|
-
let { id: categoryId, name: categoryName, parent, isActive } = category
|
186
|
-
|
187
|
-
return {
|
188
|
-
categoryId,
|
189
|
-
categoryName,
|
190
|
-
parent,
|
191
|
-
isActive: isActive || true,
|
192
|
-
channelCode,
|
193
|
-
countryCode,
|
194
|
-
childrenCategories: []
|
195
|
-
}
|
196
|
-
})
|
197
|
-
|
198
|
-
if (store.platform == 'magento') {
|
199
|
-
let newList = []
|
200
|
-
for (let np of mappedProducts) {
|
201
|
-
if (np.productId == np.variations[0].variationId) {
|
202
|
-
let vars = mappedProducts
|
203
|
-
.filter(e => e.productId == np.productId)
|
204
|
-
.map(e => {
|
205
|
-
return e.variations[0]
|
206
|
-
})
|
207
|
-
np.variations = vars
|
208
|
-
if (np.variations.length > 1) {
|
209
|
-
np.variations = np.variations.filter(v => v.variationId != np.productId)
|
210
|
-
}
|
211
|
-
newList.push(np)
|
212
|
-
}
|
213
|
-
}
|
214
|
-
mappedProducts = newList
|
215
|
-
}
|
216
|
-
|
217
|
-
try {
|
218
|
-
let filterList = []
|
219
|
-
mappedCategories = mappedCategories.map(category => {
|
220
|
-
if (mappedCategories.filter(e => e.parent == category.categoryId).length > 0) {
|
221
|
-
category.childrenCategories = mappedCategories.filter(e => e.parent == category.categoryId)
|
222
|
-
filterList.push(...mappedCategories.filter(e => e.parent == category.categoryId))
|
223
|
-
}
|
224
|
-
return category
|
225
|
-
})
|
226
|
-
|
227
|
-
mappedCategories = mappedCategories
|
228
|
-
.map(mc => {
|
229
|
-
if (filterList.indexOf(mc) == -1) {
|
230
|
-
return mc
|
231
|
-
}
|
232
|
-
})
|
233
|
-
.filter(e => e)
|
234
|
-
|
235
|
-
await SellercraftChannelIntegrationAPI.ingestChannelCategories(sellercraftStore, {
|
236
|
-
categories: mappedCategories
|
237
|
-
})
|
238
|
-
} catch (e) {
|
239
|
-
errors.push({
|
240
|
-
name: 'Category Ingestion Error',
|
241
|
-
msg: JSON.stringify(e) || {}
|
242
|
-
})
|
243
|
-
}
|
244
|
-
|
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
|
-
}
|
261
|
-
}
|
262
|
-
}
|
263
|
-
} catch (e) {
|
264
|
-
errors.push({
|
265
|
-
name: 'Product Processing / Mapping Error',
|
266
|
-
msg: JSON.stringify(e) || {}
|
267
|
-
})
|
268
|
-
}
|
269
|
-
}
|
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
|
279
|
-
}
|
280
|
-
return true
|
281
|
-
}
|
282
|
-
}
|
@@ -1,76 +0,0 @@
|
|
1
|
-
import { Field, ID, ObjectType } from 'type-graphql'
|
2
|
-
import {
|
3
|
-
Column,
|
4
|
-
CreateDateColumn,
|
5
|
-
Entity,
|
6
|
-
Index,
|
7
|
-
ManyToOne,
|
8
|
-
PrimaryGeneratedColumn,
|
9
|
-
RelationId,
|
10
|
-
UpdateDateColumn
|
11
|
-
} from 'typeorm'
|
12
|
-
|
13
|
-
import { User } from '@things-factory/auth-base'
|
14
|
-
import { Domain } from '@things-factory/shell'
|
15
|
-
|
16
|
-
@Entity()
|
17
|
-
@Index(
|
18
|
-
'ix_marketplace_channel_0 ',
|
19
|
-
(marketplaceChannel: MarketplaceChannel) => [marketplaceChannel.domain, marketplaceChannel.name],
|
20
|
-
{ unique: true }
|
21
|
-
)
|
22
|
-
@ObjectType({ description: 'Entity for Marketplace Channel' })
|
23
|
-
export class MarketplaceChannel {
|
24
|
-
@PrimaryGeneratedColumn('uuid')
|
25
|
-
@Field(type => ID)
|
26
|
-
readonly id: string
|
27
|
-
|
28
|
-
@ManyToOne(type => Domain)
|
29
|
-
@Field(type => Domain)
|
30
|
-
domain?: Domain
|
31
|
-
|
32
|
-
@RelationId((marketplaceChannel: MarketplaceChannel) => marketplaceChannel.domain)
|
33
|
-
domainId?: string
|
34
|
-
|
35
|
-
@Column()
|
36
|
-
@Field()
|
37
|
-
name: string
|
38
|
-
|
39
|
-
@Column()
|
40
|
-
@Field()
|
41
|
-
channelCode: string
|
42
|
-
|
43
|
-
@Column()
|
44
|
-
@Field()
|
45
|
-
channelId: string
|
46
|
-
|
47
|
-
@Column({ nullable: true })
|
48
|
-
@Field({ nullable: true })
|
49
|
-
countryCode: string
|
50
|
-
|
51
|
-
@Column({ default: true })
|
52
|
-
@Field()
|
53
|
-
isActive: boolean
|
54
|
-
|
55
|
-
@CreateDateColumn()
|
56
|
-
@Field({ nullable: true })
|
57
|
-
createdAt?: Date
|
58
|
-
|
59
|
-
@UpdateDateColumn()
|
60
|
-
@Field({ nullable: true })
|
61
|
-
updatedAt?: Date
|
62
|
-
|
63
|
-
@ManyToOne(type => User, { nullable: true })
|
64
|
-
@Field(type => User, { nullable: true })
|
65
|
-
creator?: User
|
66
|
-
|
67
|
-
@RelationId((marketplaceChannel: MarketplaceChannel) => marketplaceChannel.creator)
|
68
|
-
creatorId?: string
|
69
|
-
|
70
|
-
@ManyToOne(type => User, { nullable: true })
|
71
|
-
@Field(type => User, { nullable: true })
|
72
|
-
updater?: User
|
73
|
-
|
74
|
-
@RelationId((marketplaceChannel: MarketplaceChannel) => marketplaceChannel.updater)
|
75
|
-
updaterId?: string
|
76
|
-
}
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import { Sellercraft } from './sellercraft'
|
2
|
-
import { SellercraftQuery } from './sellercraft-query'
|
3
|
-
import { SellercraftMutation } from './sellercraft-mutation'
|
4
|
-
|
5
|
-
export const entities = [Sellercraft]
|
6
|
-
export const resolvers = [SellercraftQuery, SellercraftMutation]
|
@@ -1,126 +0,0 @@
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
2
|
-
import { In } from 'typeorm'
|
3
|
-
import { v4 as uuidv4 } from 'uuid'
|
4
|
-
|
5
|
-
import { Sellercraft, SellercraftPlatform, SellercraftStatus } from './sellercraft'
|
6
|
-
import { NewSellercraft, SellercraftPatch } from './sellercraft-type'
|
7
|
-
|
8
|
-
@Resolver(Sellercraft)
|
9
|
-
export class SellercraftMutation {
|
10
|
-
@Directive('@transaction')
|
11
|
-
@Mutation(returns => Sellercraft, { description: 'To create new Sellercraft' })
|
12
|
-
async createSellercraft(
|
13
|
-
@Arg('sellercraft') sellercraft: NewSellercraft,
|
14
|
-
@Ctx() context: ResolverContext
|
15
|
-
): Promise<Sellercraft> {
|
16
|
-
const { domain, user, tx } = context.state
|
17
|
-
|
18
|
-
return await tx.getRepository(Sellercraft).save({
|
19
|
-
...sellercraft,
|
20
|
-
name: uuidv4(),
|
21
|
-
domain,
|
22
|
-
creator: user,
|
23
|
-
updater: user
|
24
|
-
})
|
25
|
-
}
|
26
|
-
|
27
|
-
@Directive('@transaction')
|
28
|
-
@Mutation(returns => Sellercraft, { description: 'To modify Sellercraft information' })
|
29
|
-
async updateSellercraft(
|
30
|
-
@Arg('id') id: string,
|
31
|
-
@Arg('patch') patch: SellercraftPatch,
|
32
|
-
@Ctx() context: ResolverContext
|
33
|
-
): Promise<Sellercraft> {
|
34
|
-
const { user, tx } = context.state
|
35
|
-
|
36
|
-
const repository = tx.getRepository(Sellercraft)
|
37
|
-
const sellercraft = await repository.findOneBy({ id })
|
38
|
-
|
39
|
-
return await repository.save({
|
40
|
-
...sellercraft,
|
41
|
-
...patch,
|
42
|
-
updater: user
|
43
|
-
})
|
44
|
-
}
|
45
|
-
|
46
|
-
@Directive('@transaction')
|
47
|
-
@Mutation(returns => [Sellercraft], { description: "To modify multiple Sellercrafts' information" })
|
48
|
-
async updateMultipleSellercraft(
|
49
|
-
@Arg('patches', type => [SellercraftPatch]) patches: SellercraftPatch[],
|
50
|
-
@Ctx() context: ResolverContext
|
51
|
-
): Promise<Sellercraft[]> {
|
52
|
-
const { domain, user, tx } = context.state
|
53
|
-
|
54
|
-
let results = []
|
55
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
56
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
57
|
-
const sellercraftRepo = tx.getRepository(Sellercraft)
|
58
|
-
|
59
|
-
if (_createRecords.length > 0) {
|
60
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
61
|
-
const newRecord = _createRecords[i]
|
62
|
-
|
63
|
-
const result = await sellercraftRepo.save({
|
64
|
-
...newRecord,
|
65
|
-
domain,
|
66
|
-
name: uuidv4(),
|
67
|
-
status: SellercraftStatus.ACTIVE,
|
68
|
-
platform: SellercraftPlatform.SELLERCRAFT,
|
69
|
-
creator: user,
|
70
|
-
updater: user
|
71
|
-
})
|
72
|
-
|
73
|
-
results.push({ ...result, cuFlag: '+' })
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
if (_updateRecords.length > 0) {
|
78
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
79
|
-
const newRecord = _updateRecords[i]
|
80
|
-
const sellercraft = await sellercraftRepo.findOneBy({ id: newRecord.id })
|
81
|
-
|
82
|
-
const result = await sellercraftRepo.save({
|
83
|
-
...sellercraft,
|
84
|
-
...newRecord,
|
85
|
-
updater: user
|
86
|
-
})
|
87
|
-
|
88
|
-
results.push({ ...result, cuFlag: 'M' })
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
return results
|
93
|
-
}
|
94
|
-
|
95
|
-
@Directive('@transaction')
|
96
|
-
@Mutation(returns => Boolean, { description: 'To delete Sellercraft' })
|
97
|
-
async deleteSellercraft(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
98
|
-
const { domain, tx } = context.state
|
99
|
-
|
100
|
-
await tx.getRepository(Sellercraft).delete({ domain: { id: domain.id }, id })
|
101
|
-
return true
|
102
|
-
}
|
103
|
-
|
104
|
-
@Directive('@transaction')
|
105
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple sellercrafts' })
|
106
|
-
async deleteSellercrafts(
|
107
|
-
@Arg('ids', type => [String]) ids: string[],
|
108
|
-
@Ctx() context: ResolverContext
|
109
|
-
): Promise<boolean> {
|
110
|
-
const { domain, tx, user } = context.state
|
111
|
-
let sellercrafts: Sellercraft[] = await tx
|
112
|
-
.getRepository(Sellercraft)
|
113
|
-
.find({ where: { domain: { id: domain.id }, id: In(ids) } })
|
114
|
-
|
115
|
-
sellercrafts = sellercrafts.map((sellercraft: Sellercraft) => {
|
116
|
-
return {
|
117
|
-
...sellercraft,
|
118
|
-
status: SellercraftStatus.TERMINATED,
|
119
|
-
updater: user
|
120
|
-
}
|
121
|
-
})
|
122
|
-
|
123
|
-
await tx.getRepository(Sellercraft).save(sellercrafts)
|
124
|
-
return true
|
125
|
-
}
|
126
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
2
|
-
|
3
|
-
import { User } from '@things-factory/auth-base'
|
4
|
-
import { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
5
|
-
|
6
|
-
import { Sellercraft } from './sellercraft'
|
7
|
-
import { SellercraftList } from './sellercraft-type'
|
8
|
-
|
9
|
-
@Resolver(Sellercraft)
|
10
|
-
export class SellercraftQuery {
|
11
|
-
@Query(returns => Sellercraft, { description: 'To fetch a Sellercraft' })
|
12
|
-
async sellercraft(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Sellercraft> {
|
13
|
-
return await getRepository(Sellercraft).findOneBy({ id })
|
14
|
-
}
|
15
|
-
|
16
|
-
@Query(returns => SellercraftList, { description: 'To fetch multiple Sellercrafts' })
|
17
|
-
async sellercrafts(
|
18
|
-
@Args(type => ListParam) params: ListParam,
|
19
|
-
@Ctx() context: ResolverContext
|
20
|
-
): Promise<SellercraftList> {
|
21
|
-
const { domain } = context.state
|
22
|
-
|
23
|
-
const convertedParams = convertListParams(params, { domain })
|
24
|
-
const [items, total] = await getRepository(Sellercraft).findAndCount(convertedParams)
|
25
|
-
|
26
|
-
return { items, total }
|
27
|
-
}
|
28
|
-
|
29
|
-
@FieldResolver(type => Domain)
|
30
|
-
async domain(@Root() sellercraft: Sellercraft): Promise<Domain> {
|
31
|
-
return await getRepository(Domain).findOneBy({ id: sellercraft.domainId })
|
32
|
-
}
|
33
|
-
|
34
|
-
@FieldResolver(type => User)
|
35
|
-
async updater(@Root() sellercraft: Sellercraft): Promise<User> {
|
36
|
-
return await getRepository(User).findOneBy({ id: sellercraft.updaterId })
|
37
|
-
}
|
38
|
-
|
39
|
-
@FieldResolver(type => User)
|
40
|
-
async creator(@Root() sellercraft: Sellercraft): Promise<User> {
|
41
|
-
return await getRepository(User).findOneBy({ id: sellercraft.creatorId })
|
42
|
-
}
|
43
|
-
}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
2
|
-
|
3
|
-
import { Sellercraft, SellercraftPlatform, SellercraftStatus } from './sellercraft'
|
4
|
-
|
5
|
-
@InputType()
|
6
|
-
export class NewSellercraft {
|
7
|
-
@Field()
|
8
|
-
name: string
|
9
|
-
|
10
|
-
@Field({ nullable: true })
|
11
|
-
description?: string
|
12
|
-
|
13
|
-
@Field(type => SellercraftPlatform, { nullable: true })
|
14
|
-
platform: SellercraftPlatform
|
15
|
-
|
16
|
-
@Field()
|
17
|
-
accountId: string
|
18
|
-
|
19
|
-
@Field(type => SellercraftStatus, { nullable: true })
|
20
|
-
status?: SellercraftStatus
|
21
|
-
}
|
22
|
-
|
23
|
-
@InputType()
|
24
|
-
export class SellercraftPatch {
|
25
|
-
@Field(type => ID, { nullable: true })
|
26
|
-
id?: string
|
27
|
-
|
28
|
-
@Field({ nullable: true })
|
29
|
-
name?: string
|
30
|
-
|
31
|
-
@Field(type => SellercraftPlatform, { nullable: true })
|
32
|
-
platform?: SellercraftPlatform
|
33
|
-
|
34
|
-
@Field({ nullable: true })
|
35
|
-
accountId?: string
|
36
|
-
|
37
|
-
@Field({ nullable: true })
|
38
|
-
description?: string
|
39
|
-
|
40
|
-
@Field(type => SellercraftStatus, { nullable: true })
|
41
|
-
status?: SellercraftStatus
|
42
|
-
|
43
|
-
@Field({ nullable: true })
|
44
|
-
cuFlag?: string
|
45
|
-
}
|
46
|
-
|
47
|
-
@ObjectType()
|
48
|
-
export class SellercraftList {
|
49
|
-
@Field(type => [Sellercraft])
|
50
|
-
items: Sellercraft[]
|
51
|
-
|
52
|
-
@Field(type => Int)
|
53
|
-
total: number
|
54
|
-
}
|
@@ -1,96 +0,0 @@
|
|
1
|
-
import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
|
2
|
-
import {
|
3
|
-
Column,
|
4
|
-
CreateDateColumn,
|
5
|
-
Entity,
|
6
|
-
Index,
|
7
|
-
ManyToOne,
|
8
|
-
PrimaryGeneratedColumn,
|
9
|
-
RelationId,
|
10
|
-
UpdateDateColumn
|
11
|
-
} from 'typeorm'
|
12
|
-
|
13
|
-
import { User } from '@things-factory/auth-base'
|
14
|
-
import { Domain, ScalarObject } from '@things-factory/shell'
|
15
|
-
|
16
|
-
export enum SellercraftStatus {
|
17
|
-
ACTIVE = 'ACTIVE',
|
18
|
-
INACTIVE = 'INACTIVE',
|
19
|
-
TERMINATED = 'TERMINATED'
|
20
|
-
}
|
21
|
-
|
22
|
-
registerEnumType(SellercraftStatus, {
|
23
|
-
name: 'SellercraftStatus',
|
24
|
-
description: 'state enumeration of a sellercraft'
|
25
|
-
})
|
26
|
-
|
27
|
-
export enum SellercraftPlatform {
|
28
|
-
SELLERCRAFT = 'SELLERCRAFT'
|
29
|
-
}
|
30
|
-
|
31
|
-
registerEnumType(SellercraftPlatform, {
|
32
|
-
name: 'SellercraftPlatform',
|
33
|
-
description: 'platform enumeration of a sellercraft'
|
34
|
-
})
|
35
|
-
|
36
|
-
@Entity()
|
37
|
-
@Index('ix_sellercraft_0', (sellercraft: Sellercraft) => [sellercraft.domain, sellercraft.name], { unique: true })
|
38
|
-
@ObjectType({ description: 'Entity for Sellercraft' })
|
39
|
-
export class Sellercraft {
|
40
|
-
@PrimaryGeneratedColumn('uuid')
|
41
|
-
@Field(type => ID)
|
42
|
-
readonly id: string
|
43
|
-
|
44
|
-
@ManyToOne(type => Domain)
|
45
|
-
@Field(type => Domain)
|
46
|
-
domain?: Domain
|
47
|
-
|
48
|
-
@RelationId((sellercraft: Sellercraft) => sellercraft.domain)
|
49
|
-
domainId?: string
|
50
|
-
|
51
|
-
@Column()
|
52
|
-
@Field()
|
53
|
-
name: string
|
54
|
-
|
55
|
-
@Column({ nullable: true })
|
56
|
-
@Field({ nullable: true })
|
57
|
-
description?: string
|
58
|
-
|
59
|
-
@Column()
|
60
|
-
@Field()
|
61
|
-
accountId: string
|
62
|
-
|
63
|
-
@Column()
|
64
|
-
@Field()
|
65
|
-
platform: SellercraftPlatform
|
66
|
-
|
67
|
-
@Column({ nullable: true })
|
68
|
-
@Field({ nullable: true })
|
69
|
-
status?: SellercraftStatus
|
70
|
-
|
71
|
-
@Column('simple-json', { nullable: true })
|
72
|
-
@Field(type => ScalarObject, { nullable: true })
|
73
|
-
sellercraftSetting?: object
|
74
|
-
|
75
|
-
@CreateDateColumn()
|
76
|
-
@Field({ nullable: true })
|
77
|
-
createdAt?: Date
|
78
|
-
|
79
|
-
@UpdateDateColumn()
|
80
|
-
@Field({ nullable: true })
|
81
|
-
updatedAt?: Date
|
82
|
-
|
83
|
-
@ManyToOne(type => User, { nullable: true })
|
84
|
-
@Field(type => User, { nullable: true })
|
85
|
-
creator?: User
|
86
|
-
|
87
|
-
@RelationId((sellercraft: Sellercraft) => sellercraft.creator)
|
88
|
-
creatorId?: string
|
89
|
-
|
90
|
-
@ManyToOne(type => User, { nullable: true })
|
91
|
-
@Field(type => User, { nullable: true })
|
92
|
-
updater?: User
|
93
|
-
|
94
|
-
@RelationId((sellercraft: Sellercraft) => sellercraft.updater)
|
95
|
-
updaterId?: string
|
96
|
-
}
|