@things-factory/product-base 8.0.0-beta.9 → 8.0.2
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,248 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In, SelectQueryBuilder } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { ProductCombinationSetting } from './product-combination-setting'
|
|
5
|
+
import { NewProductCombinationSetting, ProductCombinationSettingPatch } from './product-combination-setting-type'
|
|
6
|
+
|
|
7
|
+
const debug = require('debug')('things-factory:product-base:productCombinationSetting')
|
|
8
|
+
|
|
9
|
+
@Resolver(ProductCombinationSetting)
|
|
10
|
+
export class ProductCombinationSettingMutation {
|
|
11
|
+
@Directive('@transaction')
|
|
12
|
+
@Mutation(returns => ProductCombinationSetting, { description: 'To create new ProductCombinationSetting' })
|
|
13
|
+
async createProductCombinationSetting(
|
|
14
|
+
@Arg('productCombinationSetting') productCombinationSetting: NewProductCombinationSetting,
|
|
15
|
+
@Ctx() context: ResolverContext
|
|
16
|
+
): Promise<ProductCombinationSetting> {
|
|
17
|
+
const { domain, user, tx } = context.state
|
|
18
|
+
|
|
19
|
+
return await tx.getRepository(ProductCombinationSetting).save({
|
|
20
|
+
...(productCombinationSetting as any),
|
|
21
|
+
domain,
|
|
22
|
+
creator: user,
|
|
23
|
+
updater: user
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Directive('@transaction')
|
|
28
|
+
@Mutation(returns => ProductCombinationSetting, { description: 'To modify ProductCombinationSetting information' })
|
|
29
|
+
async updateProductCombinationSetting(
|
|
30
|
+
@Arg('id') id: string,
|
|
31
|
+
@Arg('patch') patch: ProductCombinationSettingPatch,
|
|
32
|
+
@Ctx() context: ResolverContext
|
|
33
|
+
): Promise<ProductCombinationSetting> {
|
|
34
|
+
const { domain, user, tx } = context.state
|
|
35
|
+
|
|
36
|
+
const repository = tx.getRepository(ProductCombinationSetting)
|
|
37
|
+
const productCombinationSetting = await repository.findOne({
|
|
38
|
+
where: { id }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return await repository.save({
|
|
42
|
+
...productCombinationSetting,
|
|
43
|
+
...patch,
|
|
44
|
+
updater: user
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Directive('@transaction')
|
|
49
|
+
@Mutation(returns => [ProductCombinationSetting], {
|
|
50
|
+
description: "To modify multiple ProductCombinationSettings' information"
|
|
51
|
+
})
|
|
52
|
+
async updateMultipleProductCombinationSetting(
|
|
53
|
+
@Arg('patches', type => [ProductCombinationSettingPatch]) patches: ProductCombinationSettingPatch[],
|
|
54
|
+
@Ctx() context: ResolverContext
|
|
55
|
+
): Promise<ProductCombinationSetting[]> {
|
|
56
|
+
const { domain, user, tx } = context.state
|
|
57
|
+
|
|
58
|
+
let results = []
|
|
59
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
60
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
61
|
+
const productCombinationSettingRepo = tx.getRepository(ProductCombinationSetting)
|
|
62
|
+
|
|
63
|
+
if (_createRecords.length > 0) {
|
|
64
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
65
|
+
const newRecord = _createRecords[i]
|
|
66
|
+
|
|
67
|
+
const result = await productCombinationSettingRepo.save({
|
|
68
|
+
...newRecord,
|
|
69
|
+
domain,
|
|
70
|
+
creator: user,
|
|
71
|
+
updater: user
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
results.push({ ...result, cuFlag: '+' })
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (_updateRecords.length > 0) {
|
|
79
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
80
|
+
const newRecord = _updateRecords[i]
|
|
81
|
+
const productCombinationSetting = await productCombinationSettingRepo.findOneBy({ id: newRecord.id })
|
|
82
|
+
|
|
83
|
+
const result = await productCombinationSettingRepo.save({
|
|
84
|
+
...productCombinationSetting,
|
|
85
|
+
...newRecord,
|
|
86
|
+
updater: user
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return results
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Directive('@transaction')
|
|
97
|
+
@Mutation(returns => Boolean, { description: 'To delete ProductCombinationSetting' })
|
|
98
|
+
async deleteProductCombinationSetting(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
99
|
+
const { domain, tx } = context.state
|
|
100
|
+
|
|
101
|
+
await tx.getRepository(ProductCombinationSetting).delete({ id })
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Directive('@transaction')
|
|
106
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple productCombinationSettings' })
|
|
107
|
+
async deleteProductCombinationSettings(
|
|
108
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
109
|
+
@Ctx() context: ResolverContext
|
|
110
|
+
): Promise<boolean> {
|
|
111
|
+
const { domain, tx } = context.state
|
|
112
|
+
|
|
113
|
+
await tx.getRepository(ProductCombinationSetting).delete({
|
|
114
|
+
id: In(ids)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return true
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Directive('@transaction')
|
|
121
|
+
@Mutation(returns => Boolean, { description: 'To link product combination for kitting process' })
|
|
122
|
+
async linkProductCombination(
|
|
123
|
+
@Arg('productCombinationId', type => String) productCombinationId: string,
|
|
124
|
+
@Arg('patches', type => [ProductCombinationSettingPatch]) patches: ProductCombinationSettingPatch[],
|
|
125
|
+
@Ctx() context: ResolverContext
|
|
126
|
+
): Promise<boolean> {
|
|
127
|
+
try {
|
|
128
|
+
const { domain, tx } = context.state
|
|
129
|
+
|
|
130
|
+
const qb: SelectQueryBuilder<ProductCombinationSetting> = tx
|
|
131
|
+
.getRepository(ProductCombinationSetting)
|
|
132
|
+
.createQueryBuilder('pbs')
|
|
133
|
+
.innerJoinAndSelect('pbs.product', 'prd')
|
|
134
|
+
.innerJoinAndSelect('pbs.productDetail', 'pd')
|
|
135
|
+
.innerJoinAndSelect('pbs.productCombination', 'pc')
|
|
136
|
+
.where('pc.id = :productCombinationId', { productCombinationId })
|
|
137
|
+
.andWhere('pc.domain_id = :domainId', { domainId: domain.id })
|
|
138
|
+
|
|
139
|
+
const existingCombinationLink = await qb.getMany()
|
|
140
|
+
|
|
141
|
+
let newCombinationLink: ProductCombinationSetting[] = patches.reduce((acc, curr) => {
|
|
142
|
+
if (
|
|
143
|
+
!existingCombinationLink.find(
|
|
144
|
+
item => item.product.id === curr.product.id && item.productDetail.id === curr.productDetail.id
|
|
145
|
+
)
|
|
146
|
+
) {
|
|
147
|
+
acc.push({
|
|
148
|
+
productCombination: { id: productCombinationId },
|
|
149
|
+
product: { id: curr.product.id },
|
|
150
|
+
productDetail: { id: curr.productDetail.id },
|
|
151
|
+
qty: curr.qty,
|
|
152
|
+
cuFlag: '+'
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
// check if there is existing bundle link but changes in bundle qty
|
|
156
|
+
else if (
|
|
157
|
+
existingCombinationLink.find(
|
|
158
|
+
item =>
|
|
159
|
+
item.product.id === curr.product.id &&
|
|
160
|
+
item.productDetail.id === curr.productDetail.id &&
|
|
161
|
+
item.qty !== curr.qty
|
|
162
|
+
)
|
|
163
|
+
) {
|
|
164
|
+
acc.push({
|
|
165
|
+
id: curr.id,
|
|
166
|
+
productCombination: { id: productCombinationId },
|
|
167
|
+
product: { id: curr.product.id },
|
|
168
|
+
productDetail: { id: curr.productDetail.id },
|
|
169
|
+
qty: curr.qty,
|
|
170
|
+
cuFlag: 'M'
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
return acc
|
|
174
|
+
}, [])
|
|
175
|
+
|
|
176
|
+
let removeCombinationLink: ProductCombinationSetting[] = existingCombinationLink.reduce((acc, curr) => {
|
|
177
|
+
if (
|
|
178
|
+
!patches.find(item => item.product.id == curr.product.id && item.productDetail.id == curr.productDetail.id)
|
|
179
|
+
) {
|
|
180
|
+
acc.push({
|
|
181
|
+
id: curr.id,
|
|
182
|
+
productCombination: { id: productCombinationId },
|
|
183
|
+
product: { id: curr.product.id },
|
|
184
|
+
productDetail: { id: curr.productDetail.id },
|
|
185
|
+
qty: curr.qty
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
return acc
|
|
189
|
+
}, [])
|
|
190
|
+
|
|
191
|
+
if (newCombinationLink.length > 0) {
|
|
192
|
+
await updateMultipleProductCombinationSetting(newCombinationLink, context)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (removeCombinationLink.length > 0) {
|
|
196
|
+
await tx.getRepository(ProductCombinationSetting).delete({
|
|
197
|
+
id: In(removeCombinationLink.map(combinationLink => combinationLink.id))
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return true
|
|
202
|
+
} catch (error) {
|
|
203
|
+
debug('link-product-combination', error)
|
|
204
|
+
throw error
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export async function updateMultipleProductCombinationSetting(patches: any, context: ResolverContext) {
|
|
210
|
+
const { domain, user, tx } = context.state
|
|
211
|
+
|
|
212
|
+
let results = []
|
|
213
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
214
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
215
|
+
const productCombinationSettingRepo = tx.getRepository(ProductCombinationSetting)
|
|
216
|
+
|
|
217
|
+
if (_createRecords.length > 0) {
|
|
218
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
219
|
+
const newRecord = _createRecords[i]
|
|
220
|
+
|
|
221
|
+
const result = await productCombinationSettingRepo.save({
|
|
222
|
+
...newRecord,
|
|
223
|
+
domain,
|
|
224
|
+
creator: user,
|
|
225
|
+
updater: user
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
results.push({ ...result, cuFlag: '+' })
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (_updateRecords.length > 0) {
|
|
233
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
234
|
+
const newRecord = _updateRecords[i]
|
|
235
|
+
const productCombinationSetting = await productCombinationSettingRepo.findOneBy({ id: newRecord.id })
|
|
236
|
+
|
|
237
|
+
const result = await productCombinationSettingRepo.save({
|
|
238
|
+
...productCombinationSetting,
|
|
239
|
+
...newRecord,
|
|
240
|
+
updater: user
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return results
|
|
248
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
import { Brackets, SelectQueryBuilder } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
+
import { buildCondition, buildQuery, convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
6
|
+
|
|
7
|
+
import { ProductCombination } from '../product-combination/product-combination'
|
|
8
|
+
import { ProductDetail } from '../product-detail/product-detail'
|
|
9
|
+
import { Product } from '../product/product'
|
|
10
|
+
import { ProductCombinationSetting } from './product-combination-setting'
|
|
11
|
+
import { ProductCombinationSettingList } from './product-combination-setting-type'
|
|
12
|
+
|
|
13
|
+
@Resolver(ProductCombinationSetting)
|
|
14
|
+
export class ProductCombinationSettingQuery {
|
|
15
|
+
@Query(returns => ProductCombinationSetting, { description: 'To fetch a ProductCombinationSetting' })
|
|
16
|
+
async productCombinationSetting(
|
|
17
|
+
@Arg('productCombinationId') productCombinationId: string,
|
|
18
|
+
@Ctx() context: ResolverContext
|
|
19
|
+
): Promise<ProductCombinationSetting[]> {
|
|
20
|
+
const productCombination: ProductCombination = await getRepository(ProductCombination).findOne({
|
|
21
|
+
where: { id: productCombinationId },
|
|
22
|
+
relations: ['productCombinationSetting']
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const productCombinationSettings: ProductCombinationSetting[] = productCombination.productCombinationSettings
|
|
26
|
+
|
|
27
|
+
return productCombinationSettings
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Query(returns => ProductCombinationSettingList, { description: 'To fetch multiple ProductCombinationSettings' })
|
|
31
|
+
async productCombinationSettings(
|
|
32
|
+
@Args(type => ListParam) params: ListParam,
|
|
33
|
+
@Ctx() context: ResolverContext
|
|
34
|
+
): Promise<ProductCombinationSettingList> {
|
|
35
|
+
const { domain } = context.state
|
|
36
|
+
|
|
37
|
+
const convertedParams = convertListParams(params, { domain })
|
|
38
|
+
const [items, total] = await getRepository(ProductCombinationSetting).findAndCount(convertedParams)
|
|
39
|
+
|
|
40
|
+
return { items, total }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Query(returns => ProductCombinationSettingList, { description: 'To fetch a set of product combinations' })
|
|
44
|
+
async productCombinationSets(
|
|
45
|
+
@Args(type => ListParam) params: ListParam,
|
|
46
|
+
@Ctx() context: ResolverContext
|
|
47
|
+
): Promise<ProductCombinationSettingList> {
|
|
48
|
+
const { domain } = context.state
|
|
49
|
+
const page = params.pagination.page
|
|
50
|
+
const limit = params.pagination.limit
|
|
51
|
+
|
|
52
|
+
const filters = params.filters.filter(
|
|
53
|
+
x => x.name !== 'product_info' && x.name !== 'productCombinationId' && x.name !== 'bizplace_id'
|
|
54
|
+
)
|
|
55
|
+
const bizplaceFilter = params.filters.find(x => x.name == 'bizplace_id')
|
|
56
|
+
const productCombinationId = params.filters.find(x => x.name === 'productCombinationId')
|
|
57
|
+
const productInfoFilter = params.filters.find(x => x.name === 'product_info')
|
|
58
|
+
const productInfoColumns = ['sku', 'name', 'description']
|
|
59
|
+
params.filters = [...filters]
|
|
60
|
+
|
|
61
|
+
params.sortings = [
|
|
62
|
+
{ name: 'prd.sku' },
|
|
63
|
+
{ name: 'prdDet.gtin' },
|
|
64
|
+
...params.sortings.map(sorting => {
|
|
65
|
+
const name = sorting.name.replace('product', '').toLowerCase()
|
|
66
|
+
return {
|
|
67
|
+
...sorting,
|
|
68
|
+
name
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
if (bizplaceFilter?.value) {
|
|
74
|
+
const bizplaceId: string = bizplaceFilter.value
|
|
75
|
+
|
|
76
|
+
const foundBizplace: Bizplace = await getRepository(Bizplace).findOne({
|
|
77
|
+
where: { id: bizplaceId } /* CONFIRMME regarding TYPEORM - migrated correctly ? */,
|
|
78
|
+
relations: ['company', 'company.domain']
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
if (foundBizplace) {
|
|
82
|
+
const companyDomain: Domain = foundBizplace.company?.domain
|
|
83
|
+
const companyBizplace: Bizplace = await getRepository(Bizplace).findOne({
|
|
84
|
+
where: { domain: { id: companyDomain.id } }
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const bizplaceIds = [companyBizplace.id, foundBizplace.id]
|
|
88
|
+
params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [...new Set(bizplaceIds)] }]
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
let bizplace: Bizplace = await getRepository(Bizplace).findOne({ where: { domain: { id: domain.id } } })
|
|
92
|
+
params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [bizplace.id] }]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const qb: SelectQueryBuilder<Product> = getRepository(Product).createQueryBuilder('prd')
|
|
96
|
+
buildQuery(qb, params, context, {
|
|
97
|
+
domainRef: false
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
qb.innerJoinAndSelect('product_details', 'prdDet', 'prdDet.product_id = prd.id')
|
|
101
|
+
qb.leftJoinAndSelect(
|
|
102
|
+
'product_combination_settings',
|
|
103
|
+
'pcs',
|
|
104
|
+
`pcs.product_id = prd.id and pcs.product_detail_id = prdDet.id ${
|
|
105
|
+
productCombinationId && productCombinationId.operator === 'noteq' ? 'and pcs.product_detail_id = null' : ''
|
|
106
|
+
}`
|
|
107
|
+
)
|
|
108
|
+
qb.leftJoinAndSelect('pcs.productCombination', 'pc')
|
|
109
|
+
|
|
110
|
+
if (productInfoFilter) {
|
|
111
|
+
qb.andWhere(
|
|
112
|
+
new Brackets(qb2 => {
|
|
113
|
+
productInfoColumns.forEach(filter => {
|
|
114
|
+
const condition = buildCondition(
|
|
115
|
+
qb.alias,
|
|
116
|
+
filter,
|
|
117
|
+
productInfoFilter.operator,
|
|
118
|
+
productInfoFilter.value,
|
|
119
|
+
productInfoFilter.relation,
|
|
120
|
+
Object.keys(qb.getParameters()).length
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
qb2.orWhere(condition.clause, condition.parameters)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (productCombinationId && productCombinationId.operator === 'eq') {
|
|
130
|
+
qb.andWhere('pc.id = :combinationId::uuid', {
|
|
131
|
+
combinationId: productCombinationId.value
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let productCombinationSets = await qb
|
|
136
|
+
.offset((page - 1) * limit)
|
|
137
|
+
.limit(limit)
|
|
138
|
+
.getRawMany()
|
|
139
|
+
|
|
140
|
+
const items = productCombinationSets.map(item => {
|
|
141
|
+
return {
|
|
142
|
+
id: item.pcs_id,
|
|
143
|
+
productDetailId: item.prdDet_id,
|
|
144
|
+
gtin: item.prdDet_gtin,
|
|
145
|
+
packingType: item.prdDet_packing_type,
|
|
146
|
+
packingSize: item.prdDet_packing_size,
|
|
147
|
+
productId: item.prd_id,
|
|
148
|
+
productSku: item.prd_sku,
|
|
149
|
+
productName: item.prd_name,
|
|
150
|
+
productDescription: item.prd_description,
|
|
151
|
+
productType: item.prd_type,
|
|
152
|
+
combinationId: item.pc_id,
|
|
153
|
+
qty: item.pcs_qty
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const total = await qb.getCount()
|
|
158
|
+
|
|
159
|
+
return { items, total }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@FieldResolver(type => Product)
|
|
163
|
+
async product(@Root() productCombinationSetting: ProductCombinationSetting): Promise<Product> {
|
|
164
|
+
return await getRepository(Product).findOneBy({ id: productCombinationSetting.productId })
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@FieldResolver(type => ProductDetail)
|
|
168
|
+
async productDetail(@Root() productCombinationSetting: ProductCombinationSetting): Promise<ProductDetail> {
|
|
169
|
+
return await getRepository(ProductDetail).findOneBy({ id: productCombinationSetting.productDetailId })
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@FieldResolver(type => ProductCombination)
|
|
173
|
+
async productCombination(@Root() productCombinationSetting: ProductCombinationSetting): Promise<ProductCombination> {
|
|
174
|
+
return await getRepository(ProductCombination).findOneBy({ id: productCombinationSetting.productCombinationId })
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
+
|
|
5
|
+
import { ProductCombinationSetting } from './product-combination-setting'
|
|
6
|
+
|
|
7
|
+
@InputType()
|
|
8
|
+
export class NewProductCombinationSetting {
|
|
9
|
+
@Field()
|
|
10
|
+
name: string
|
|
11
|
+
|
|
12
|
+
@Field({ nullable: true })
|
|
13
|
+
description?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@InputType()
|
|
17
|
+
export class ProductCombinationSettingPatch {
|
|
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
|
+
productCombination?: ObjectRef
|
|
29
|
+
|
|
30
|
+
@Field(type => Int)
|
|
31
|
+
qty: number
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
cuFlag?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ObjectType()
|
|
38
|
+
export class ProductCombinationSettingList {
|
|
39
|
+
@Field(type => [ProductCombinationSetting])
|
|
40
|
+
items: ProductCombinationSetting[]
|
|
41
|
+
|
|
42
|
+
@Field(type => Int)
|
|
43
|
+
total: number
|
|
44
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Field, ID, ObjectType, Int } from 'type-graphql'
|
|
2
|
+
import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { ProductCombination } from '../product-combination/product-combination'
|
|
5
|
+
import { ProductDetail } from '../product-detail/product-detail'
|
|
6
|
+
import { Product } from '../product/product'
|
|
7
|
+
|
|
8
|
+
@Entity()
|
|
9
|
+
@Index(
|
|
10
|
+
'ix_product_combination_setting_0',
|
|
11
|
+
(productCombinationSetting: ProductCombinationSetting) => [
|
|
12
|
+
productCombinationSetting.product,
|
|
13
|
+
productCombinationSetting.productDetail,
|
|
14
|
+
productCombinationSetting.productCombination
|
|
15
|
+
],
|
|
16
|
+
{ unique: true }
|
|
17
|
+
)
|
|
18
|
+
@ObjectType({ description: 'Entity for ProductCombinationSetting' })
|
|
19
|
+
export class ProductCombinationSetting {
|
|
20
|
+
@PrimaryGeneratedColumn('uuid')
|
|
21
|
+
@Field(type => ID, { nullable: true })
|
|
22
|
+
readonly id?: string
|
|
23
|
+
|
|
24
|
+
@ManyToOne(type => Product)
|
|
25
|
+
@Field(type => Product)
|
|
26
|
+
product?: Product
|
|
27
|
+
|
|
28
|
+
@RelationId((productCombinationSetting: ProductCombinationSetting) => productCombinationSetting.product)
|
|
29
|
+
@Field({ nullable: true })
|
|
30
|
+
productId?: string
|
|
31
|
+
|
|
32
|
+
@ManyToOne(type => ProductDetail)
|
|
33
|
+
@Field(type => ProductDetail)
|
|
34
|
+
productDetail?: ProductDetail
|
|
35
|
+
|
|
36
|
+
@RelationId((productCombinationSetting: ProductCombinationSetting) => productCombinationSetting.productDetail)
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
productDetailId?: string
|
|
39
|
+
|
|
40
|
+
@ManyToOne(type => ProductCombination)
|
|
41
|
+
@Field(type => ProductCombination)
|
|
42
|
+
productCombination?: ProductCombination
|
|
43
|
+
|
|
44
|
+
@RelationId((productCombinationSetting: ProductCombinationSetting) => productCombinationSetting.productCombination)
|
|
45
|
+
productCombinationId?: string
|
|
46
|
+
|
|
47
|
+
@Column({ nullable: true })
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
qty: number
|
|
50
|
+
|
|
51
|
+
@Field({ nullable: true })
|
|
52
|
+
gtin?: string
|
|
53
|
+
|
|
54
|
+
@Field({ nullable: true })
|
|
55
|
+
packingType?: string
|
|
56
|
+
|
|
57
|
+
@Field(type => Int, { nullable: true })
|
|
58
|
+
packingSize?: number
|
|
59
|
+
|
|
60
|
+
@Field({ nullable: true })
|
|
61
|
+
remainUomValueWithUom?: string
|
|
62
|
+
|
|
63
|
+
@Field({ nullable: true })
|
|
64
|
+
productSku?: string
|
|
65
|
+
|
|
66
|
+
@Field({ nullable: true })
|
|
67
|
+
productName?: string
|
|
68
|
+
|
|
69
|
+
@Field({ nullable: true })
|
|
70
|
+
productDescription?: string
|
|
71
|
+
|
|
72
|
+
@Field({ nullable: true })
|
|
73
|
+
productType?: string
|
|
74
|
+
|
|
75
|
+
@Field({ nullable: true })
|
|
76
|
+
combinationId?: string
|
|
77
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProductDetail } from './product-detail'
|
|
2
|
+
import { ProductDetailMutation } from './product-detail-mutation'
|
|
3
|
+
import { ProductDetailQuery } from './product-detail-query'
|
|
4
|
+
|
|
5
|
+
export const entities = [ProductDetail]
|
|
6
|
+
export const resolvers = [ProductDetailQuery, ProductDetailMutation]
|