@things-factory/product-base 8.0.0-beta.9 → 8.0.0
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/service/product/product-mutation.js +1 -1
- package/dist-server/service/product/product-mutation.js.map +1 -1
- package/dist-server/service/product/product-query.d.ts +1 -1
- package/dist-server/service/product/product-query.js +5 -5
- package/dist-server/service/product/product-query.js.map +1 -1
- package/dist-server/service/product/product-types.d.ts +4 -2
- package/dist-server/service/product/product-types.js +10 -2
- package/dist-server/service/product/product-types.js.map +1 -1
- package/dist-server/service/product/product.d.ts +2 -1
- package/dist-server/service/product/product.js +6 -1
- package/dist-server/service/product/product.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/server/constants/index.ts +1 -0
- package/server/constants/product.ts +24 -0
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +2 -0
- package/server/middlewares/index.ts +0 -0
- package/server/migrations/index.ts +9 -0
- package/server/service/index.ts +61 -0
- package/server/service/product/index.ts +6 -0
- package/server/service/product/product-mutation.ts +407 -0
- package/server/service/product/product-query.ts +336 -0
- package/server/service/product/product-types.ts +458 -0
- package/server/service/product/product.ts +548 -0
- package/server/service/product/validate-product.ts +42 -0
- package/server/service/product-bundle/index.ts +6 -0
- package/server/service/product-bundle/product-bundle-mutation.ts +140 -0
- package/server/service/product-bundle/product-bundle-query.ts +104 -0
- package/server/service/product-bundle/product-bundle-types.ts +51 -0
- package/server/service/product-bundle/product-bundle.ts +102 -0
- package/server/service/product-bundle-setting/index.ts +6 -0
- package/server/service/product-bundle-setting/product-bundle-setting-mutation.ts +168 -0
- package/server/service/product-bundle-setting/product-bundle-setting-query.ts +139 -0
- package/server/service/product-bundle-setting/product-bundle-setting-types.ts +41 -0
- package/server/service/product-bundle-setting/product-bundle-setting.ts +45 -0
- package/server/service/product-combination/index.ts +6 -0
- package/server/service/product-combination/product-combination-mutation.ts +148 -0
- package/server/service/product-combination/product-combination-query.ts +48 -0
- package/server/service/product-combination/product-combination-type.ts +50 -0
- package/server/service/product-combination/product-combination.ts +116 -0
- package/server/service/product-combination-setting/index.ts +6 -0
- package/server/service/product-combination-setting/product-combination-setting-mutation.ts +248 -0
- package/server/service/product-combination-setting/product-combination-setting-query.ts +176 -0
- package/server/service/product-combination-setting/product-combination-setting-type.ts +44 -0
- package/server/service/product-combination-setting/product-combination-setting.ts +77 -0
- package/server/service/product-detail/index.ts +6 -0
- package/server/service/product-detail/product-detail-mutation.ts +238 -0
- package/server/service/product-detail/product-detail-query.ts +213 -0
- package/server/service/product-detail/product-detail-types.ts +280 -0
- package/server/service/product-detail/product-detail.ts +388 -0
- package/server/service/product-detail-bizplace-setting/index.ts +6 -0
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-mutation.ts +118 -0
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-query.ts +90 -0
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-types.ts +62 -0
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting.ts +104 -0
- package/server/service/product-set/index.ts +6 -0
- package/server/service/product-set/product-set-mutation.ts +149 -0
- package/server/service/product-set/product-set-query.ts +114 -0
- package/server/service/product-set/product-set-types.ts +45 -0
- package/server/service/product-set/product-set.ts +95 -0
- package/server/utils/index.ts +1 -0
- package/server/utils/product-util.ts +11 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Args, Ctx, Query, Resolver } from 'type-graphql'
|
|
2
|
+
import { Brackets, SelectQueryBuilder } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
+
import { buildCondition, buildQuery, convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
6
|
+
|
|
7
|
+
import { Product } from '../product/product'
|
|
8
|
+
import { ProductBundleSetting } from './product-bundle-setting'
|
|
9
|
+
import { ProductBundleSettingList } from './product-bundle-setting-types'
|
|
10
|
+
|
|
11
|
+
@Resolver(ProductBundleSetting)
|
|
12
|
+
export class ProductBundleSettingQuery {
|
|
13
|
+
@Query(returns => ProductBundleSettingList)
|
|
14
|
+
async productBundleSettings(
|
|
15
|
+
@Args(type => ListParam) params: ListParam,
|
|
16
|
+
@Ctx() context: ResolverContext
|
|
17
|
+
): Promise<ProductBundleSettingList> {
|
|
18
|
+
const convertedParams = convertListParams(params)
|
|
19
|
+
const [items, total] = await getRepository(ProductBundleSetting).findAndCount({
|
|
20
|
+
...convertedParams
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return { items, total }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Query(returns => ProductBundleSettingList)
|
|
27
|
+
async productBundleSets(
|
|
28
|
+
@Args(type => ListParam) params: ListParam,
|
|
29
|
+
@Ctx() context: ResolverContext
|
|
30
|
+
): Promise<ProductBundleSettingList> {
|
|
31
|
+
const { domain } = context.state
|
|
32
|
+
const page = params.pagination.page
|
|
33
|
+
const limit = params.pagination.limit
|
|
34
|
+
|
|
35
|
+
const filters = params.filters.filter(x => x.name !== 'product_info' && x.name !== 'productBundleId')
|
|
36
|
+
const productBundleId = params.filters.find(x => x.name === 'productBundleId')
|
|
37
|
+
const productInfoFilter = params.filters.find(x => x.name === 'product_info')
|
|
38
|
+
const productInfoColumns = ['sku', 'name', 'description']
|
|
39
|
+
params.filters = [...filters]
|
|
40
|
+
|
|
41
|
+
params.sortings = [
|
|
42
|
+
{ name: 'prd.sku' },
|
|
43
|
+
{ name: 'prdDet.gtin' },
|
|
44
|
+
...params.sortings.map(sorting => {
|
|
45
|
+
const name = sorting.name.replace('product', '').toLowerCase()
|
|
46
|
+
return {
|
|
47
|
+
...sorting,
|
|
48
|
+
name
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
if (!params.filters.find(filter => filter.name === 'bizplace_id')) {
|
|
54
|
+
let bizplace: Bizplace = await getRepository(Bizplace).findOne({ where: { domain: { id: domain.id } } })
|
|
55
|
+
params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [bizplace.id] }]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const qb: SelectQueryBuilder<Product> = getRepository(Product).createQueryBuilder('prd')
|
|
59
|
+
buildQuery(qb, params, context)
|
|
60
|
+
|
|
61
|
+
qb.innerJoinAndSelect('product_details', 'prdDet', 'prdDet.product_id = prd.id')
|
|
62
|
+
qb.leftJoinAndSelect(
|
|
63
|
+
'product_bundle_settings',
|
|
64
|
+
'pbs',
|
|
65
|
+
'pbs.product_id = prd.id and pbs.product_detail_id = prdDet.id'
|
|
66
|
+
)
|
|
67
|
+
qb.leftJoinAndSelect('pbs.productBundle', 'pb')
|
|
68
|
+
|
|
69
|
+
if (productInfoFilter) {
|
|
70
|
+
qb.andWhere(
|
|
71
|
+
new Brackets(qb2 => {
|
|
72
|
+
productInfoColumns.forEach(filter => {
|
|
73
|
+
const condition = buildCondition(
|
|
74
|
+
qb.alias,
|
|
75
|
+
filter,
|
|
76
|
+
productInfoFilter.operator,
|
|
77
|
+
productInfoFilter.value,
|
|
78
|
+
productInfoFilter.relation,
|
|
79
|
+
Object.keys(qb.getParameters()).length
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
qb2.orWhere(condition.clause, condition.parameters)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (productBundleId && productBundleId.operator === 'eq') {
|
|
89
|
+
qb.andWhere('pb.id = :bundleId::uuid', {
|
|
90
|
+
bundleId: productBundleId.value
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let productBundleSets = await qb
|
|
95
|
+
.offset((page - 1) * limit)
|
|
96
|
+
.limit(limit)
|
|
97
|
+
.getRawMany()
|
|
98
|
+
|
|
99
|
+
const items = productBundleSets.map(item => {
|
|
100
|
+
return {
|
|
101
|
+
// id: item.pbs_id,
|
|
102
|
+
// productDetailId: item.prdDet_id,
|
|
103
|
+
// gtin: item.prdDet_gtin,
|
|
104
|
+
// packingType: item.prdDet_packing_type,
|
|
105
|
+
// packingSize: item.prdDet_packing_size,
|
|
106
|
+
// productId: item.prd_id,
|
|
107
|
+
// productSku: item.prd_sku,
|
|
108
|
+
// productName: item.prd_name,
|
|
109
|
+
// productDescription: item.prd_description,
|
|
110
|
+
// productType: item.prd_type,
|
|
111
|
+
// bundleId: item.pb_id,
|
|
112
|
+
// bundleSku: item.pb_sku,
|
|
113
|
+
// bundleName: item.pb_name,
|
|
114
|
+
// bundleDescription: item.pb_description,
|
|
115
|
+
// bundleQty: item.pbs_bundle_qty
|
|
116
|
+
...item,
|
|
117
|
+
id: item.pbs_id,
|
|
118
|
+
product: {
|
|
119
|
+
id: item.prd_id,
|
|
120
|
+
sku: item.prd_sku,
|
|
121
|
+
name: item.prd_name,
|
|
122
|
+
description: item.prd_description,
|
|
123
|
+
type: item.prd_type
|
|
124
|
+
},
|
|
125
|
+
productDetail: {
|
|
126
|
+
id: item.prdDet_id,
|
|
127
|
+
gtin: item.prdDet_gtin,
|
|
128
|
+
packingType: item.prdDet_packing_type,
|
|
129
|
+
packingSize: item.prdDet_packing_size
|
|
130
|
+
},
|
|
131
|
+
bundleQty: item.pbs_bundle_qty
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const total = await qb.getCount()
|
|
136
|
+
|
|
137
|
+
return { items, total }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Field, Float, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { ProductBundleSetting } from './product-bundle-setting'
|
|
6
|
+
|
|
7
|
+
@ObjectType()
|
|
8
|
+
export class ProductBundleSettingList {
|
|
9
|
+
@Field(type => [ProductBundleSetting], { nullable: true })
|
|
10
|
+
items?: ProductBundleSetting[]
|
|
11
|
+
|
|
12
|
+
@Field(type => Int, { nullable: true })
|
|
13
|
+
total?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@InputType()
|
|
17
|
+
export class ProductBundleSettingPatch {
|
|
18
|
+
@Field(type => ID, { nullable: true })
|
|
19
|
+
id?: string
|
|
20
|
+
|
|
21
|
+
@Field({ nullable: true })
|
|
22
|
+
product?: ObjectRef
|
|
23
|
+
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
productDetail?: ObjectRef
|
|
26
|
+
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
productBundle?: ObjectRef
|
|
29
|
+
|
|
30
|
+
@Field(type => Int, { nullable: true })
|
|
31
|
+
bundleQty?: number
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
packingType?: string
|
|
35
|
+
|
|
36
|
+
@Field(type => Float, { nullable: true })
|
|
37
|
+
packingSize?: number
|
|
38
|
+
|
|
39
|
+
@Field({ nullable: true })
|
|
40
|
+
cuFlag?: string
|
|
41
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { ProductBundle } from '../product-bundle/product-bundle'
|
|
5
|
+
import { ProductDetail } from '../product-detail/product-detail'
|
|
6
|
+
import { Product } from '../product/product'
|
|
7
|
+
|
|
8
|
+
@Entity()
|
|
9
|
+
@Index(
|
|
10
|
+
'ix_product_bundle_setting_0',
|
|
11
|
+
(productBundleSetting: ProductBundleSetting) => [
|
|
12
|
+
productBundleSetting.product,
|
|
13
|
+
productBundleSetting.productDetail,
|
|
14
|
+
productBundleSetting.productBundle
|
|
15
|
+
],
|
|
16
|
+
{ unique: true }
|
|
17
|
+
)
|
|
18
|
+
@ObjectType()
|
|
19
|
+
export class ProductBundleSetting {
|
|
20
|
+
@PrimaryGeneratedColumn('uuid')
|
|
21
|
+
@Field(type => ID, { nullable: true })
|
|
22
|
+
readonly id?: string
|
|
23
|
+
|
|
24
|
+
@ManyToOne(type => Product, { nullable: true })
|
|
25
|
+
@Field(type => Product, { nullable: true })
|
|
26
|
+
product?: Product
|
|
27
|
+
|
|
28
|
+
@ManyToOne(type => ProductDetail, { nullable: true })
|
|
29
|
+
@Field(type => ProductDetail, { nullable: true })
|
|
30
|
+
productDetail?: ProductDetail
|
|
31
|
+
|
|
32
|
+
@ManyToOne(type => ProductBundle, { nullable: true })
|
|
33
|
+
@Field(type => ProductBundle, { nullable: true })
|
|
34
|
+
productBundle?: ProductBundle
|
|
35
|
+
|
|
36
|
+
@Column({ nullable: true })
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
bundleQty?: number
|
|
39
|
+
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
productId?: string
|
|
42
|
+
|
|
43
|
+
@Field({ nullable: true })
|
|
44
|
+
bundleId?: string
|
|
45
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProductCombination } from './product-combination'
|
|
2
|
+
import { ProductCombinationQuery } from './product-combination-query'
|
|
3
|
+
import { ProductCombinationMutation } from './product-combination-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [ProductCombination]
|
|
6
|
+
export const resolvers = [ProductCombinationQuery, ProductCombinationMutation]
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In, Repository } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { ProductDetail } from '../product-detail/product-detail'
|
|
5
|
+
import { ProductCombination, ProductCombinationStatus } from './product-combination'
|
|
6
|
+
import { NewProductCombination, ProductCombinationPatch } from './product-combination-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(ProductCombination)
|
|
9
|
+
export class ProductCombinationMutation {
|
|
10
|
+
@Directive('@transaction')
|
|
11
|
+
@Mutation(returns => ProductCombination, { description: 'To create new ProductCombination' })
|
|
12
|
+
async createProductCombination(
|
|
13
|
+
@Arg('productCombination') productCombination: NewProductCombination,
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<ProductCombination> {
|
|
16
|
+
const { domain, user, tx } = context.state
|
|
17
|
+
|
|
18
|
+
return await tx.getRepository(ProductCombination).save({
|
|
19
|
+
...productCombination,
|
|
20
|
+
domain,
|
|
21
|
+
creator: user,
|
|
22
|
+
updater: user
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Directive('@transaction')
|
|
27
|
+
@Mutation(returns => ProductCombination, { description: 'To modify ProductCombination information' })
|
|
28
|
+
async updateProductCombination(
|
|
29
|
+
@Arg('id') id: string,
|
|
30
|
+
@Arg('patch') patch: ProductCombinationPatch,
|
|
31
|
+
@Ctx() context: ResolverContext
|
|
32
|
+
): Promise<ProductCombination> {
|
|
33
|
+
const { domain, user, tx } = context.state
|
|
34
|
+
|
|
35
|
+
const repository = tx.getRepository(ProductCombination)
|
|
36
|
+
const productCombination = await repository.findOne({
|
|
37
|
+
where: { domain: { id: domain.id }, id }
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return await repository.save({
|
|
41
|
+
...productCombination,
|
|
42
|
+
...patch,
|
|
43
|
+
updater: user
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Directive('@transaction')
|
|
48
|
+
@Mutation(returns => [ProductCombination], { description: "To modify multiple ProductCombinations' information" })
|
|
49
|
+
async updateMultipleProductCombination(
|
|
50
|
+
@Arg('productDetailId', type => String) productDetailId: string,
|
|
51
|
+
@Arg('patches', type => [ProductCombinationPatch]) patches: ProductCombinationPatch[],
|
|
52
|
+
@Ctx() context: ResolverContext
|
|
53
|
+
): Promise<ProductCombination[]> {
|
|
54
|
+
const { domain, user, tx } = context.state
|
|
55
|
+
|
|
56
|
+
let results = []
|
|
57
|
+
const _createRecords = patches.filter((patch: any) => !patch.id)
|
|
58
|
+
const _updateRecords = patches.filter((patch: any) => patch.id)
|
|
59
|
+
const productDetailRepo = tx.getRepository(ProductDetail)
|
|
60
|
+
const productCombinationRepo = tx.getRepository(ProductCombination)
|
|
61
|
+
|
|
62
|
+
if (_createRecords.length > 0) {
|
|
63
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
64
|
+
let newRecord = _createRecords[i]
|
|
65
|
+
const productDetail: ProductDetail = await productDetailRepo.findOne({
|
|
66
|
+
where: { id: productDetailId },
|
|
67
|
+
relations: ['product']
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
delete newRecord.id
|
|
71
|
+
|
|
72
|
+
if (!newRecord?.status) {
|
|
73
|
+
newRecord.status = ProductCombinationStatus.INACTIVE
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const result = await productCombinationRepo.save({
|
|
77
|
+
...newRecord,
|
|
78
|
+
domain,
|
|
79
|
+
productDetail,
|
|
80
|
+
product: productDetail.product,
|
|
81
|
+
status: newRecord.status.toUpperCase(),
|
|
82
|
+
creator: user,
|
|
83
|
+
updater: user
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
results.push({ ...result, cuFlag: '+' })
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (_updateRecords.length > 0) {
|
|
91
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
92
|
+
const newRecord = _updateRecords[i]
|
|
93
|
+
const productCombination = await productCombinationRepo.findOneBy({
|
|
94
|
+
domain: { id: domain.id },
|
|
95
|
+
id: newRecord.id
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
if (newRecord.status) {
|
|
99
|
+
newRecord.status = newRecord.status.toUpperCase()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const result = await productCombinationRepo.save({
|
|
103
|
+
...productCombination,
|
|
104
|
+
...newRecord,
|
|
105
|
+
updater: user
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return results
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Directive('@transaction')
|
|
116
|
+
@Mutation(returns => Boolean, { description: 'To delete ProductCombination' })
|
|
117
|
+
async deleteProductCombination(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
118
|
+
const { user, tx } = context.state
|
|
119
|
+
|
|
120
|
+
await tx.getRepository(ProductCombination).update({ id }, { deletedAt: new Date(), deletedBy: user })
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@Directive('@transaction')
|
|
125
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple productCombinations' })
|
|
126
|
+
async deleteProductCombinations(
|
|
127
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
128
|
+
@Ctx() context: ResolverContext
|
|
129
|
+
): Promise<boolean> {
|
|
130
|
+
const { user, tx } = context.state
|
|
131
|
+
|
|
132
|
+
const productCombinationRepo: Repository<ProductCombination> = tx.getRepository(ProductCombination)
|
|
133
|
+
|
|
134
|
+
let productCombinations = await productCombinationRepo.find({ where: { id: In(ids) } })
|
|
135
|
+
|
|
136
|
+
for (let i = 0; i < productCombinations.length; i++) {
|
|
137
|
+
const product = productCombinations[i]
|
|
138
|
+
|
|
139
|
+
await productCombinationRepo.save({
|
|
140
|
+
...product,
|
|
141
|
+
status: ProductCombinationStatus.DELETED,
|
|
142
|
+
updater: user
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return true
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { ProductCombination } from './product-combination'
|
|
7
|
+
import { ProductCombinationList } from './product-combination-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(ProductCombination)
|
|
10
|
+
export class ProductCombinationQuery {
|
|
11
|
+
@Query(returns => ProductCombination, { description: 'To fetch a ProductCombination' })
|
|
12
|
+
async productCombination(@Arg('id') name: string, @Ctx() context: ResolverContext): Promise<ProductCombination> {
|
|
13
|
+
const { domain, tx } = context.state
|
|
14
|
+
|
|
15
|
+
return await tx.getRepository(ProductCombination).findOne({
|
|
16
|
+
where: { domain: { id: domain.id }, name }
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Query(returns => ProductCombinationList, { description: 'To fetch multiple ProductCombinations' })
|
|
21
|
+
async productCombinations(
|
|
22
|
+
@Args(type => ListParam) params: ListParam,
|
|
23
|
+
@Ctx() context: ResolverContext
|
|
24
|
+
): Promise<ProductCombinationList> {
|
|
25
|
+
const convertedParams = convertListParams(params)
|
|
26
|
+
const [items, total] = await getRepository(ProductCombination).findAndCount({
|
|
27
|
+
...convertedParams,
|
|
28
|
+
relations: ['product', 'productDetail']
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return { items, total }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@FieldResolver(type => Domain)
|
|
35
|
+
async domain(@Root() productCombination: ProductCombination): Promise<Domain> {
|
|
36
|
+
return await getRepository(Domain).findOneBy({ id: productCombination.domainId })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@FieldResolver(type => User)
|
|
40
|
+
async updater(@Root() productCombination: ProductCombination): Promise<User> {
|
|
41
|
+
return await getRepository(User).findOneBy({ id: productCombination.updaterId })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@FieldResolver(type => User)
|
|
45
|
+
async creator(@Root() productCombination: ProductCombination): Promise<User> {
|
|
46
|
+
return await getRepository(User).findOneBy({ id: productCombination.creatorId })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { ProductCombination, ProductCombinationStatus } from './product-combination'
|
|
6
|
+
|
|
7
|
+
@InputType()
|
|
8
|
+
export class NewProductCombination {
|
|
9
|
+
@Field()
|
|
10
|
+
name: string
|
|
11
|
+
|
|
12
|
+
@Field({ nullable: true })
|
|
13
|
+
description?: string
|
|
14
|
+
|
|
15
|
+
@Field(type => ProductCombinationStatus, { nullable: true })
|
|
16
|
+
status?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@InputType()
|
|
20
|
+
export class ProductCombinationPatch {
|
|
21
|
+
@Field(type => ID, { nullable: true })
|
|
22
|
+
id?: string
|
|
23
|
+
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
name?: string
|
|
26
|
+
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
description?: string
|
|
29
|
+
|
|
30
|
+
@Field({ nullable: true })
|
|
31
|
+
status?: string
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
product?: ObjectRef
|
|
35
|
+
|
|
36
|
+
@Field({ nullable: true })
|
|
37
|
+
productDetail?: ObjectRef
|
|
38
|
+
|
|
39
|
+
@Field({ nullable: true })
|
|
40
|
+
cuFlag?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ObjectType()
|
|
44
|
+
export class ProductCombinationList {
|
|
45
|
+
@Field(type => [ProductCombination])
|
|
46
|
+
items: ProductCombination[]
|
|
47
|
+
|
|
48
|
+
@Field(type => Int)
|
|
49
|
+
total: number
|
|
50
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
CreateDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
ManyToOne,
|
|
8
|
+
OneToMany,
|
|
9
|
+
PrimaryGeneratedColumn,
|
|
10
|
+
RelationId,
|
|
11
|
+
UpdateDateColumn
|
|
12
|
+
} from 'typeorm'
|
|
13
|
+
|
|
14
|
+
import { User } from '@things-factory/auth-base'
|
|
15
|
+
import { Domain } from '@things-factory/shell'
|
|
16
|
+
|
|
17
|
+
import { ProductCombinationSetting } from '../product-combination-setting/product-combination-setting'
|
|
18
|
+
import { ProductDetail } from '../product-detail/product-detail'
|
|
19
|
+
import { Product } from '../product/product'
|
|
20
|
+
|
|
21
|
+
export enum ProductCombinationStatus {
|
|
22
|
+
ACTIVE = 'ACTIVE',
|
|
23
|
+
ACTIVATED = 'ACTIVATED',
|
|
24
|
+
DELETED = 'DELETED',
|
|
25
|
+
INACTIVE = 'INACTIVE'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
registerEnumType(ProductCombinationStatus, {
|
|
29
|
+
name: 'ProductCombinationStatus',
|
|
30
|
+
description: 'status enumeration of a productCombination'
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
@Entity()
|
|
34
|
+
@Index(
|
|
35
|
+
'ix_product_combination_0',
|
|
36
|
+
(productCombination: ProductCombination) => [productCombination.domain, productCombination.id],
|
|
37
|
+
{ unique: true }
|
|
38
|
+
)
|
|
39
|
+
@ObjectType({ description: 'Entity for ProductCombination' })
|
|
40
|
+
export class ProductCombination {
|
|
41
|
+
@PrimaryGeneratedColumn('uuid')
|
|
42
|
+
@Field(type => ID)
|
|
43
|
+
readonly id: string
|
|
44
|
+
|
|
45
|
+
@ManyToOne(type => Domain)
|
|
46
|
+
@Field(type => Domain)
|
|
47
|
+
domain?: Domain
|
|
48
|
+
|
|
49
|
+
@RelationId((productCombination: ProductCombination) => productCombination.domain)
|
|
50
|
+
domainId?: string
|
|
51
|
+
|
|
52
|
+
@Column()
|
|
53
|
+
@Field()
|
|
54
|
+
name: string
|
|
55
|
+
|
|
56
|
+
@OneToMany(
|
|
57
|
+
type => ProductCombinationSetting,
|
|
58
|
+
productCombinationSetting => productCombinationSetting.productCombination
|
|
59
|
+
)
|
|
60
|
+
@Field(type => [ProductCombinationSetting], { nullable: true })
|
|
61
|
+
productCombinationSettings?: ProductCombinationSetting[]
|
|
62
|
+
|
|
63
|
+
@ManyToOne(type => Product)
|
|
64
|
+
@Field(type => Product)
|
|
65
|
+
product?: Product
|
|
66
|
+
|
|
67
|
+
@RelationId((productCombination: ProductCombination) => productCombination.product)
|
|
68
|
+
productId?: string
|
|
69
|
+
|
|
70
|
+
@ManyToOne(type => ProductDetail, { nullable: false })
|
|
71
|
+
@Field(type => ProductDetail)
|
|
72
|
+
productDetail?: ProductDetail
|
|
73
|
+
|
|
74
|
+
@RelationId((productCombination: ProductCombination) => productCombination.productDetail)
|
|
75
|
+
productDetailId?: string
|
|
76
|
+
|
|
77
|
+
@Column({ nullable: true })
|
|
78
|
+
@Field({ nullable: true })
|
|
79
|
+
description?: string
|
|
80
|
+
|
|
81
|
+
@Column({ nullable: true })
|
|
82
|
+
deletedAt: Date
|
|
83
|
+
|
|
84
|
+
@ManyToOne(type => User, { nullable: true })
|
|
85
|
+
@Field({ nullable: true })
|
|
86
|
+
deletedBy: User
|
|
87
|
+
|
|
88
|
+
@RelationId((productCombination: ProductCombination) => productCombination.deletedBy)
|
|
89
|
+
deletedById?: string
|
|
90
|
+
|
|
91
|
+
@Column({ nullable: true })
|
|
92
|
+
@Field({ nullable: true })
|
|
93
|
+
status?: string
|
|
94
|
+
|
|
95
|
+
@CreateDateColumn()
|
|
96
|
+
@Field({ nullable: true })
|
|
97
|
+
createdAt?: Date
|
|
98
|
+
|
|
99
|
+
@UpdateDateColumn()
|
|
100
|
+
@Field({ nullable: true })
|
|
101
|
+
updatedAt?: Date
|
|
102
|
+
|
|
103
|
+
@ManyToOne(type => User, { nullable: true })
|
|
104
|
+
@Field(type => User, { nullable: true })
|
|
105
|
+
creator?: User
|
|
106
|
+
|
|
107
|
+
@RelationId((productCombination: ProductCombination) => productCombination.creator)
|
|
108
|
+
creatorId?: string
|
|
109
|
+
|
|
110
|
+
@ManyToOne(type => User, { nullable: true })
|
|
111
|
+
@Field(type => User, { nullable: true })
|
|
112
|
+
updater?: User
|
|
113
|
+
|
|
114
|
+
@RelationId((productCombination: ProductCombination) => productCombination.updater)
|
|
115
|
+
updaterId?: string
|
|
116
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProductCombinationSetting } from './product-combination-setting'
|
|
2
|
+
import { ProductCombinationSettingQuery } from './product-combination-setting-query'
|
|
3
|
+
import { ProductCombinationSettingMutation } from './product-combination-setting-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [ProductCombinationSetting]
|
|
6
|
+
export const resolvers = [ProductCombinationSettingQuery, ProductCombinationSettingMutation]
|