@things-factory/product-base 8.0.0 → 9.0.0-beta.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/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 +2 -4
- package/dist-server/service/product/product-types.js +2 -10
- package/dist-server/service/product/product-types.js.map +1 -1
- package/dist-server/service/product/product.d.ts +1 -2
- package/dist-server/service/product/product.js +1 -6
- 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 +0 -1
- package/server/constants/product.ts +0 -24
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +0 -2
- package/server/middlewares/index.ts +0 -0
- package/server/migrations/index.ts +0 -9
- package/server/service/index.ts +0 -61
- package/server/service/product/index.ts +0 -6
- package/server/service/product/product-mutation.ts +0 -407
- package/server/service/product/product-query.ts +0 -336
- package/server/service/product/product-types.ts +0 -458
- package/server/service/product/product.ts +0 -548
- package/server/service/product/validate-product.ts +0 -42
- package/server/service/product-bundle/index.ts +0 -6
- package/server/service/product-bundle/product-bundle-mutation.ts +0 -140
- package/server/service/product-bundle/product-bundle-query.ts +0 -104
- package/server/service/product-bundle/product-bundle-types.ts +0 -51
- package/server/service/product-bundle/product-bundle.ts +0 -102
- package/server/service/product-bundle-setting/index.ts +0 -6
- package/server/service/product-bundle-setting/product-bundle-setting-mutation.ts +0 -168
- package/server/service/product-bundle-setting/product-bundle-setting-query.ts +0 -139
- package/server/service/product-bundle-setting/product-bundle-setting-types.ts +0 -41
- package/server/service/product-bundle-setting/product-bundle-setting.ts +0 -45
- package/server/service/product-combination/index.ts +0 -6
- package/server/service/product-combination/product-combination-mutation.ts +0 -148
- package/server/service/product-combination/product-combination-query.ts +0 -48
- package/server/service/product-combination/product-combination-type.ts +0 -50
- package/server/service/product-combination/product-combination.ts +0 -116
- package/server/service/product-combination-setting/index.ts +0 -6
- package/server/service/product-combination-setting/product-combination-setting-mutation.ts +0 -248
- package/server/service/product-combination-setting/product-combination-setting-query.ts +0 -176
- package/server/service/product-combination-setting/product-combination-setting-type.ts +0 -44
- package/server/service/product-combination-setting/product-combination-setting.ts +0 -77
- package/server/service/product-detail/index.ts +0 -6
- package/server/service/product-detail/product-detail-mutation.ts +0 -238
- package/server/service/product-detail/product-detail-query.ts +0 -213
- package/server/service/product-detail/product-detail-types.ts +0 -280
- package/server/service/product-detail/product-detail.ts +0 -388
- package/server/service/product-detail-bizplace-setting/index.ts +0 -6
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-mutation.ts +0 -118
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-query.ts +0 -90
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-types.ts +0 -62
- package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting.ts +0 -104
- package/server/service/product-set/index.ts +0 -6
- package/server/service/product-set/product-set-mutation.ts +0 -149
- package/server/service/product-set/product-set-query.ts +0 -114
- package/server/service/product-set/product-set-types.ts +0 -45
- package/server/service/product-set/product-set.ts +0 -95
- package/server/utils/index.ts +0 -1
- package/server/utils/product-util.ts +0 -11
package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-mutation.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { getRepository } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { ProductDetail } from '../product-detail/product-detail'
|
|
7
|
-
import { ProductDetailBizplaceSetting } from './product-detail-bizplace-setting'
|
|
8
|
-
import { ProductDetailBizplaceSettingPatch } from './product-detail-bizplace-setting-types'
|
|
9
|
-
|
|
10
|
-
@Resolver(ProductDetailBizplaceSetting)
|
|
11
|
-
export class ProductDetailBizplaceSettingMutation {
|
|
12
|
-
@Mutation(returns => ProductDetailBizplaceSetting)
|
|
13
|
-
async updateProductDetailBizplaceSetting(
|
|
14
|
-
@Arg('name') name: string,
|
|
15
|
-
@Arg('patch') patch: ProductDetailBizplaceSettingPatch,
|
|
16
|
-
@Ctx() context: ResolverContext
|
|
17
|
-
): Promise<ProductDetailBizplaceSetting> {
|
|
18
|
-
const { domain, user } = context.state
|
|
19
|
-
|
|
20
|
-
const repository = getRepository(ProductDetailBizplaceSetting)
|
|
21
|
-
const productDetailBizplaceSetting = await repository.findOne({
|
|
22
|
-
where: { domain: { id: domain.id }, name }
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
return await repository.save({
|
|
26
|
-
...productDetailBizplaceSetting,
|
|
27
|
-
...patch,
|
|
28
|
-
updater: user
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@Directive('@transaction')
|
|
33
|
-
@Mutation(returns => [ProductDetailBizplaceSetting])
|
|
34
|
-
async updateMultipleProductDetailBizplaceSetting(
|
|
35
|
-
@Arg('productId') productId: string,
|
|
36
|
-
@Arg('patches', type => [ProductDetailBizplaceSettingPatch]) patches: ProductDetailBizplaceSettingPatch[],
|
|
37
|
-
@Ctx() context: ResolverContext
|
|
38
|
-
): Promise<ProductDetailBizplaceSettingPatch[]> {
|
|
39
|
-
const { domain, user, tx } = context.state
|
|
40
|
-
|
|
41
|
-
let results = []
|
|
42
|
-
const _createRecords = patches.filter((patch: any) => !patch.id)
|
|
43
|
-
const _updateRecords = patches.filter((patch: any) => patch.id)
|
|
44
|
-
|
|
45
|
-
const productDetailBizplaceSettingRepo = tx.getRepository(ProductDetailBizplaceSetting)
|
|
46
|
-
|
|
47
|
-
if (_createRecords.length > 0) {
|
|
48
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
49
|
-
const newRecord = _createRecords[i]
|
|
50
|
-
delete newRecord.id
|
|
51
|
-
|
|
52
|
-
const productDetail = await tx.getRepository(ProductDetail).findOneBy({ id: newRecord.productDetail.id })
|
|
53
|
-
|
|
54
|
-
if (productDetail) {
|
|
55
|
-
const result = await productDetailBizplaceSettingRepo.save({
|
|
56
|
-
...newRecord,
|
|
57
|
-
name: productDetail.gtin,
|
|
58
|
-
productDetail,
|
|
59
|
-
domain: domain,
|
|
60
|
-
creator: user,
|
|
61
|
-
updater: user
|
|
62
|
-
})
|
|
63
|
-
results.push({ ...result, cuFlag: '+' })
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (_updateRecords.length > 0) {
|
|
69
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
70
|
-
const newRecord = _updateRecords[i]
|
|
71
|
-
const productDetailBizplaceSetting = await productDetailBizplaceSettingRepo.findOneBy({
|
|
72
|
-
domain: { id: domain.id },
|
|
73
|
-
id: newRecord.id
|
|
74
|
-
})
|
|
75
|
-
const productDetail = await tx.getRepository(ProductDetail).findOneBy({ id: newRecord.productDetail.id })
|
|
76
|
-
|
|
77
|
-
const result = await productDetailBizplaceSettingRepo.save({
|
|
78
|
-
...productDetailBizplaceSetting,
|
|
79
|
-
...newRecord,
|
|
80
|
-
name: productDetail.gtin,
|
|
81
|
-
productDetail,
|
|
82
|
-
updater: user
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return results
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@Mutation(returns => Boolean)
|
|
93
|
-
async deleteProductDetailBizplaceSetting(
|
|
94
|
-
@Arg('name') name: string,
|
|
95
|
-
@Ctx() context: ResolverContext
|
|
96
|
-
): Promise<Boolean> {
|
|
97
|
-
const { domain } = context.state
|
|
98
|
-
|
|
99
|
-
await getRepository(ProductDetailBizplaceSetting).delete({ domain: { id: domain.id }, name })
|
|
100
|
-
|
|
101
|
-
return true
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@Mutation(returns => Boolean)
|
|
105
|
-
async deleteProductDetailBizplaceSettings(
|
|
106
|
-
@Arg('names', type => [String]) names: string[],
|
|
107
|
-
@Ctx() context: ResolverContext
|
|
108
|
-
): Promise<Boolean> {
|
|
109
|
-
const { domain } = context.state
|
|
110
|
-
|
|
111
|
-
await getRepository(ProductDetailBizplaceSetting).delete({
|
|
112
|
-
domain: { id: domain.id },
|
|
113
|
-
name: In(names)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
return true
|
|
117
|
-
}
|
|
118
|
-
}
|
package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-query.ts
DELETED
|
@@ -1,90 +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 { buildQuery, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
-
|
|
6
|
-
import { ProductDetail } from '../product-detail/product-detail'
|
|
7
|
-
import { ProductDetailBizplaceSetting } from './product-detail-bizplace-setting'
|
|
8
|
-
import { ProductDetailBizplaceSettingList } from './product-detail-bizplace-setting-types'
|
|
9
|
-
|
|
10
|
-
@Resolver(ProductDetailBizplaceSetting)
|
|
11
|
-
export class ProductDetailBizplaceSettingQuery {
|
|
12
|
-
@Query(returns => ProductDetailBizplaceSetting)
|
|
13
|
-
async productDetailBizplaceSetting(
|
|
14
|
-
@Arg('name') name: string,
|
|
15
|
-
@Ctx() context: ResolverContext
|
|
16
|
-
): Promise<ProductDetailBizplaceSetting> {
|
|
17
|
-
const { domain } = context.state
|
|
18
|
-
const repository = getRepository(ProductDetailBizplaceSetting)
|
|
19
|
-
|
|
20
|
-
return await repository.findOne({
|
|
21
|
-
where: { domain: { id: domain.id }, name }
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Query(returns => ProductDetailBizplaceSettingList)
|
|
26
|
-
async productDetailBizplaceSettings(
|
|
27
|
-
@Args(type => ListParam) params: ListParam,
|
|
28
|
-
@Ctx() context: ResolverContext
|
|
29
|
-
): Promise<ProductDetailBizplaceSettingList> {
|
|
30
|
-
const { domain, user: updater }: { domain: Domain; user: User } = context.state
|
|
31
|
-
|
|
32
|
-
const queryBuilder = getRepository(ProductDetail).createQueryBuilder('productDetail')
|
|
33
|
-
|
|
34
|
-
buildQuery(queryBuilder, params, context, {
|
|
35
|
-
domainRef: false
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
let qb = queryBuilder
|
|
39
|
-
.leftJoinAndSelect(
|
|
40
|
-
'productDetail.productDetailBizplaceSettings',
|
|
41
|
-
'pdbs',
|
|
42
|
-
'"pdbs"."product_detail_id"="productDetail"."id"'
|
|
43
|
-
)
|
|
44
|
-
.leftJoinAndSelect('productDetail.domain', 'domain')
|
|
45
|
-
.leftJoinAndSelect('productDetail.creator', 'creator')
|
|
46
|
-
.leftJoinAndSelect('productDetail.updater', 'updater')
|
|
47
|
-
|
|
48
|
-
// qb.andWhere('pdbs.bizplace_id = :bizplaceId', { bizplaceId: bizplace.id })
|
|
49
|
-
|
|
50
|
-
const [items, total] = await qb.getManyAndCount()
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
items: items.map(itm => {
|
|
54
|
-
let productDetailBizplaceSetting = itm.productDetailBizplaceSettings[0]
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
requirePacking: false,
|
|
58
|
-
bufferQty: 0,
|
|
59
|
-
minQty: 0,
|
|
60
|
-
maxQty: 0,
|
|
61
|
-
productDetail: itm,
|
|
62
|
-
...productDetailBizplaceSetting
|
|
63
|
-
}
|
|
64
|
-
}),
|
|
65
|
-
total
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// const convertedParams = convertListParams(params)
|
|
69
|
-
// const [items, total] = await getRepository(ProductDetailBizplaceSettingEntity).findAndCount({
|
|
70
|
-
// ...convertedParams
|
|
71
|
-
// })
|
|
72
|
-
|
|
73
|
-
// return { items, total }
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@FieldResolver(type => Domain)
|
|
77
|
-
async domain(@Root() productDetailBizplaceSetting: ProductDetailBizplaceSetting): Promise<Domain> {
|
|
78
|
-
return await getRepository(Domain).findOneBy({ id: productDetailBizplaceSetting.domain.id })
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@FieldResolver(type => User)
|
|
82
|
-
async updater(@Root() productDetailBizplaceSetting: ProductDetailBizplaceSetting): Promise<User> {
|
|
83
|
-
return await getRepository(User).findOneBy({ id: productDetailBizplaceSetting.updater.id })
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@FieldResolver(type => User)
|
|
87
|
-
async creator(@Root() productDetailBizplaceSetting: ProductDetailBizplaceSetting): Promise<User> {
|
|
88
|
-
return await getRepository(User).findOneBy({ id: productDetailBizplaceSetting.creator.id })
|
|
89
|
-
}
|
|
90
|
-
}
|
package/server/service/product-detail-bizplace-setting/product-detail-bizplace-setting-types.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Field, Float, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { ObjectRef } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { ProductDetailBizplaceSetting } from './product-detail-bizplace-setting'
|
|
6
|
-
|
|
7
|
-
@InputType()
|
|
8
|
-
export class NewProductDetailBizplaceSetting {
|
|
9
|
-
@Field()
|
|
10
|
-
name: string
|
|
11
|
-
|
|
12
|
-
@Field({ nullable: true })
|
|
13
|
-
productDetail?: ObjectRef
|
|
14
|
-
|
|
15
|
-
@Field({ nullable: true })
|
|
16
|
-
requirePacking?: boolean
|
|
17
|
-
|
|
18
|
-
@Field(type => Int, { nullable: true })
|
|
19
|
-
bufferQty?: number
|
|
20
|
-
|
|
21
|
-
@Field(type => Float, { nullable: true })
|
|
22
|
-
minQty?: number
|
|
23
|
-
|
|
24
|
-
@Field(type => Float, { nullable: true })
|
|
25
|
-
maxQty?: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@ObjectType()
|
|
29
|
-
export class ProductDetailBizplaceSettingList {
|
|
30
|
-
@Field(type => [ProductDetailBizplaceSetting], { nullable: true })
|
|
31
|
-
items?: ProductDetailBizplaceSetting[]
|
|
32
|
-
|
|
33
|
-
@Field(type => Int, { nullable: true })
|
|
34
|
-
total?: number
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@InputType()
|
|
38
|
-
export class ProductDetailBizplaceSettingPatch {
|
|
39
|
-
@Field({ nullable: true })
|
|
40
|
-
id?: string
|
|
41
|
-
|
|
42
|
-
@Field({ nullable: true })
|
|
43
|
-
name?: string
|
|
44
|
-
|
|
45
|
-
@Field({ nullable: true })
|
|
46
|
-
productDetail?: ObjectRef
|
|
47
|
-
|
|
48
|
-
@Field({ nullable: true })
|
|
49
|
-
requirePacking?: boolean
|
|
50
|
-
|
|
51
|
-
@Field(type => Int, { nullable: true })
|
|
52
|
-
bufferQty?: number
|
|
53
|
-
|
|
54
|
-
@Field(type => Float, { nullable: true })
|
|
55
|
-
minQty?: number
|
|
56
|
-
|
|
57
|
-
@Field(type => Float, { nullable: true })
|
|
58
|
-
maxQty?: number
|
|
59
|
-
|
|
60
|
-
@Field({ nullable: true })
|
|
61
|
-
cuFlag?: string
|
|
62
|
-
}
|
|
@@ -1,104 +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, roundTransformer } from '@things-factory/shell'
|
|
15
|
-
|
|
16
|
-
import { ProductDetail } from '../product-detail/product-detail'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @prop {string} id - Primary Key.
|
|
20
|
-
* @prop {Object} domain - Foreign field. Relation to Domain Entity / Table.
|
|
21
|
-
* @prop {Object} productDetail - Foreign field. Relation to Product Detail Entity / Table.
|
|
22
|
-
* @prop {string} name - Product Detail Name.
|
|
23
|
-
* @prop {boolean} requirePacking - Default SKU info.
|
|
24
|
-
* @prop {?number} bufferQty - Quantity for reservation.
|
|
25
|
-
* @prop {?number} minQty - Minimum Quantity targetted in inventory. For reporting purposes.
|
|
26
|
-
* @prop {?number} maxQty - Maximum Quantity targetted in inventory. For reporting purposes.
|
|
27
|
-
* @prop {Date} createdAt - Created Date and Time.
|
|
28
|
-
* @prop {Date} updatedAt - Updated Date and Time.
|
|
29
|
-
* @prop {?Object} creator - Foreign field. Relation to User Entity / Table.
|
|
30
|
-
* @prop {?Object} updater - Foreign field. Relation to User Entity / Table.
|
|
31
|
-
**/
|
|
32
|
-
|
|
33
|
-
@Entity()
|
|
34
|
-
@Index(
|
|
35
|
-
'ix_product_detail_bizplace_setting_0',
|
|
36
|
-
(productDetailBizplaceSetting: ProductDetailBizplaceSetting) => [
|
|
37
|
-
productDetailBizplaceSetting.domain,
|
|
38
|
-
productDetailBizplaceSetting.productDetail
|
|
39
|
-
],
|
|
40
|
-
{ unique: true }
|
|
41
|
-
)
|
|
42
|
-
@ObjectType()
|
|
43
|
-
export class ProductDetailBizplaceSetting {
|
|
44
|
-
@PrimaryGeneratedColumn('uuid')
|
|
45
|
-
@Field(type => ID)
|
|
46
|
-
readonly id: string
|
|
47
|
-
|
|
48
|
-
@ManyToOne(type => Domain)
|
|
49
|
-
@Field(type => Domain)
|
|
50
|
-
domain: Domain
|
|
51
|
-
|
|
52
|
-
@RelationId((productDetailBizplaceSetting: ProductDetailBizplaceSetting) => productDetailBizplaceSetting.domain)
|
|
53
|
-
domainId: string
|
|
54
|
-
|
|
55
|
-
@ManyToOne(type => ProductDetail)
|
|
56
|
-
@Field(type => ProductDetail)
|
|
57
|
-
productDetail: ProductDetail
|
|
58
|
-
|
|
59
|
-
@Column()
|
|
60
|
-
@Field()
|
|
61
|
-
name: string
|
|
62
|
-
|
|
63
|
-
@Column({ default: false })
|
|
64
|
-
@Field()
|
|
65
|
-
requirePacking: boolean
|
|
66
|
-
|
|
67
|
-
@Column({ default: 0 })
|
|
68
|
-
@Field()
|
|
69
|
-
bufferQty: number
|
|
70
|
-
|
|
71
|
-
@Column('float', { default: 0, transformer: roundTransformer })
|
|
72
|
-
@Field()
|
|
73
|
-
minQty: number
|
|
74
|
-
|
|
75
|
-
@Column('float', { default: 0, transformer: roundTransformer })
|
|
76
|
-
@Field()
|
|
77
|
-
maxQty: number
|
|
78
|
-
|
|
79
|
-
@CreateDateColumn()
|
|
80
|
-
@Field({ nullable: true })
|
|
81
|
-
createdAt: Date
|
|
82
|
-
|
|
83
|
-
@UpdateDateColumn()
|
|
84
|
-
@Field({ nullable: true })
|
|
85
|
-
updatedAt: Date
|
|
86
|
-
|
|
87
|
-
@ManyToOne(type => User, {
|
|
88
|
-
nullable: true
|
|
89
|
-
})
|
|
90
|
-
@Field({ nullable: true })
|
|
91
|
-
creator: User
|
|
92
|
-
|
|
93
|
-
@RelationId((productDetailBizplaceSetting: ProductDetailBizplaceSetting) => productDetailBizplaceSetting.creator)
|
|
94
|
-
creatorId: string
|
|
95
|
-
|
|
96
|
-
@ManyToOne(type => User, {
|
|
97
|
-
nullable: true
|
|
98
|
-
})
|
|
99
|
-
@Field({ nullable: true })
|
|
100
|
-
updater: User
|
|
101
|
-
|
|
102
|
-
@RelationId((productDetailBizplaceSetting: ProductDetailBizplaceSetting) => productDetailBizplaceSetting.updater)
|
|
103
|
-
updaterId: string
|
|
104
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { Repository } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
-
|
|
6
|
-
import { PRODUCT_SET_STATUS } from '../../constants'
|
|
7
|
-
import { ProductUtil } from '../../utils'
|
|
8
|
-
import { ProductSet } from './product-set'
|
|
9
|
-
import { NewProductSet, ProductSetPatch } from './product-set-types'
|
|
10
|
-
|
|
11
|
-
@Resolver(ProductSet)
|
|
12
|
-
export class ProductSetMutation {
|
|
13
|
-
@Directive('@privilege(category: "order", privilege: "mutation")')
|
|
14
|
-
@Directive('@transaction')
|
|
15
|
-
@Mutation(returns => ProductSet)
|
|
16
|
-
async createProductSet(
|
|
17
|
-
@Arg('productSet') productSet: NewProductSet,
|
|
18
|
-
@Ctx() context: ResolverContext
|
|
19
|
-
): Promise<ProductSet> {
|
|
20
|
-
return await createProductSet(productSet, context)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Directive('@privilege(category: "order", privilege: "mutation")')
|
|
24
|
-
@Directive('@transaction')
|
|
25
|
-
@Mutation(returns => ProductSet)
|
|
26
|
-
async updateProductSet(
|
|
27
|
-
@Arg('id') id: string,
|
|
28
|
-
@Arg('patch') patch: ProductSetPatch,
|
|
29
|
-
@Ctx() context: ResolverContext
|
|
30
|
-
): Promise<ProductSet> {
|
|
31
|
-
return await updateProductSet(id, patch, context)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@Directive('@privilege(category: "order", privilege: "mutation")')
|
|
35
|
-
@Directive('@transaction')
|
|
36
|
-
@Mutation(returns => [ProductSet])
|
|
37
|
-
async updateMultipleProductSet(
|
|
38
|
-
@Arg('patches', type => [ProductSetPatch]) patches: ProductSetPatch[],
|
|
39
|
-
@Ctx() context: ResolverContext
|
|
40
|
-
): Promise<ProductSet[]> {
|
|
41
|
-
let results = []
|
|
42
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
43
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
44
|
-
|
|
45
|
-
if (_createRecords.length > 0) {
|
|
46
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
47
|
-
const patch = _createRecords[i]
|
|
48
|
-
const result = await createProductSet(patch as NewProductSet, context)
|
|
49
|
-
results.push({ ...result, cuFlag: '+' })
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (_updateRecords.length > 0) {
|
|
54
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
55
|
-
const patch: ProductSetPatch = _updateRecords[i]
|
|
56
|
-
const result = await updateProductSet(patch.id, patch, context)
|
|
57
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return results
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@Directive('@privilege(category: "order", privilege: "mutation")')
|
|
65
|
-
@Directive('@transaction')
|
|
66
|
-
@Mutation(returns => Boolean)
|
|
67
|
-
async deleteProductSet(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {
|
|
68
|
-
const { tx, user } = context.state
|
|
69
|
-
const productSetRepo: Repository<ProductSet> = tx.getRepository(ProductSet)
|
|
70
|
-
const productSet = await productSetRepo.findOneBy({ id })
|
|
71
|
-
|
|
72
|
-
await productSetRepo.save({
|
|
73
|
-
...productSet,
|
|
74
|
-
status: PRODUCT_SET_STATUS.DELETED,
|
|
75
|
-
updater: user
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
return true
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@Directive('@privilege(category: "order", privilege: "mutation")')
|
|
82
|
-
@Directive('@transaction')
|
|
83
|
-
@Mutation(returns => Boolean)
|
|
84
|
-
async deleteProductSets(
|
|
85
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
86
|
-
@Ctx() context: ResolverContext
|
|
87
|
-
): Promise<Boolean> {
|
|
88
|
-
const { tx, user } = context.state
|
|
89
|
-
const productSetRepo = tx.getRepository(ProductSet)
|
|
90
|
-
|
|
91
|
-
let results = []
|
|
92
|
-
let productSets = productSetRepo.findByIds(ids)
|
|
93
|
-
|
|
94
|
-
for (let i = 0; i < (await productSets).length; i++) {
|
|
95
|
-
const productSet = productSets[i]
|
|
96
|
-
|
|
97
|
-
const result = await productSetRepo.save({
|
|
98
|
-
...productSet,
|
|
99
|
-
status: PRODUCT_SET_STATUS.DELETED,
|
|
100
|
-
updater: user
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
results.push({ ...result })
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return true
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function createProductSet(productSet: NewProductSet, context: ResolverContext) {
|
|
111
|
-
const { domain, user, tx } = context.state
|
|
112
|
-
|
|
113
|
-
const productSetRepo: Repository<ProductSet> = tx.getRepository(ProductSet)
|
|
114
|
-
const bizplaceRepo: Repository<Bizplace> = tx.getRepository(Bizplace)
|
|
115
|
-
|
|
116
|
-
let bizplace: Bizplace
|
|
117
|
-
// if (productSet.bizplace?.id) {
|
|
118
|
-
// bizplace = await bizplaceRepo.findOneBy({ id: productSet.bizplace.id })
|
|
119
|
-
// } else {
|
|
120
|
-
// bizplace = await bizplaceRepo.findOne({ where: { name: domain.name } })
|
|
121
|
-
// }
|
|
122
|
-
bizplace = await bizplaceRepo.findOne({ where: { name: domain.name } })
|
|
123
|
-
|
|
124
|
-
return await productSetRepo.save({
|
|
125
|
-
...productSet,
|
|
126
|
-
code: ProductUtil.productSetCode(),
|
|
127
|
-
bizplace,
|
|
128
|
-
creator: user,
|
|
129
|
-
updater: user
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function updateProductSet(
|
|
134
|
-
id: string,
|
|
135
|
-
patch: ProductSetPatch,
|
|
136
|
-
context: ResolverContext
|
|
137
|
-
): Promise<ProductSet> {
|
|
138
|
-
const { user, tx } = context.state
|
|
139
|
-
|
|
140
|
-
const bizplaceRepo: Repository<Bizplace> = tx.getRepository(Bizplace)
|
|
141
|
-
const productRepo: Repository<ProductSet> = tx.getRepository(ProductSet)
|
|
142
|
-
const productSet = await productRepo.findOneBy({ id })
|
|
143
|
-
|
|
144
|
-
return productRepo.save({
|
|
145
|
-
...productSet,
|
|
146
|
-
...patch,
|
|
147
|
-
updater: user
|
|
148
|
-
})
|
|
149
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { Brackets, SelectQueryBuilder } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Bizplace, getCompanyBizplace, getMyBizplace } from '@things-factory/biz-base'
|
|
6
|
-
import { buildCondition, buildQuery, convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'
|
|
7
|
-
|
|
8
|
-
import { ProductSet } from './product-set'
|
|
9
|
-
import { ProductSetList } from './product-set-types'
|
|
10
|
-
|
|
11
|
-
@Resolver(ProductSet)
|
|
12
|
-
export class ProductSetQuery {
|
|
13
|
-
@Directive('@privilege(category: "order", privilege: "query", domainOwnerGranted: true)')
|
|
14
|
-
@Query(returns => ProductSetList)
|
|
15
|
-
async myBizplaceProductSets(
|
|
16
|
-
@Args(type => ListParam) params: ListParam,
|
|
17
|
-
@Ctx() context: ResolverContext
|
|
18
|
-
): Promise<ProductSetList> {
|
|
19
|
-
const { domain, user } = context.state
|
|
20
|
-
const qb: SelectQueryBuilder<ProductSet> = getRepository(ProductSet).createQueryBuilder()
|
|
21
|
-
|
|
22
|
-
const productFilters = params.filters.filter(x => x.name == 'product_set_info')
|
|
23
|
-
const filters = params.filters.filter(x => x.name != 'product_set_info')
|
|
24
|
-
const productFilterColumns = ['name', 'description']
|
|
25
|
-
|
|
26
|
-
if (!params.filters.find(filter => filter.name === 'bizplace_id')) {
|
|
27
|
-
const companyBizplace: Bizplace = await getCompanyBizplace(domain, user)
|
|
28
|
-
const myBizplace: Bizplace = await getMyBizplace(domain, user)
|
|
29
|
-
params.filters = [...filters, { name: 'bizplace_id', operator: 'in', value: [companyBizplace.id, myBizplace.id] }]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
buildQuery(qb, params, context, { domainRef: false })
|
|
33
|
-
if (productFilters && productFilters.length > 0) {
|
|
34
|
-
let productInfo = productFilters[0]
|
|
35
|
-
qb.andWhere(
|
|
36
|
-
new Brackets(qb2 => {
|
|
37
|
-
productFilterColumns.forEach(filter => {
|
|
38
|
-
const condition = buildCondition(
|
|
39
|
-
qb.alias,
|
|
40
|
-
filter,
|
|
41
|
-
productInfo.operator,
|
|
42
|
-
productInfo.value,
|
|
43
|
-
productInfo.relation,
|
|
44
|
-
Object.keys(qb.getParameters()).length
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
qb2.orWhere(condition.clause, condition.parameters)
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const [items, total] = await qb
|
|
54
|
-
.leftJoinAndSelect('ProductSet.bizplace', 'Bizplace')
|
|
55
|
-
.leftJoinAndSelect('ProductSet.creator', 'Creator')
|
|
56
|
-
.leftJoinAndSelect('ProductSet.updater', 'Updater')
|
|
57
|
-
.leftJoinAndSelect('ProductSet.product', 'Product')
|
|
58
|
-
.getManyAndCount()
|
|
59
|
-
|
|
60
|
-
return { items, total }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Directive('@privilege(category: "order", privilege: "query", domainOwnerGranted: true)')
|
|
64
|
-
@Query(returns => ProductSetList)
|
|
65
|
-
async productSets(
|
|
66
|
-
@Args(type => ListParam) params: ListParam,
|
|
67
|
-
@Ctx() context: ResolverContext
|
|
68
|
-
): Promise<ProductSetList> {
|
|
69
|
-
const { domain, user } = context.state
|
|
70
|
-
|
|
71
|
-
if (!params.filters.find((filter: any) => filter.name === 'bizplace_id')) {
|
|
72
|
-
let bizplaceFilter = params.filters.find((filter: any) => filter.name === 'bizplace_id')
|
|
73
|
-
const companyBizplace: Bizplace = await getCompanyBizplace(domain, user)
|
|
74
|
-
const myBizplace: Bizplace = await getMyBizplace(domain, user)
|
|
75
|
-
|
|
76
|
-
bizplaceFilter = { name: 'bizplace_id', operator: 'in', value: [companyBizplace.id, myBizplace.id] }
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const convertedParams = convertListParams(params)
|
|
80
|
-
const [items, total] = await getRepository(ProductSet).findAndCount({
|
|
81
|
-
...convertedParams,
|
|
82
|
-
relations: ['domain', 'creator', 'updater', 'product']
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
return { items, total }
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@Directive('@privilege(category: "order", privilege: "query", domainOwnerGranted: true)')
|
|
89
|
-
@Query(returns => ProductSet)
|
|
90
|
-
async productSet(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<ProductSet> {
|
|
91
|
-
const { domain, user } = context.state
|
|
92
|
-
const repository = getRepository(ProductSet)
|
|
93
|
-
|
|
94
|
-
return await repository.findOne({
|
|
95
|
-
where: { domain: { id: domain.id }, name },
|
|
96
|
-
relations: ['domain', 'creator', 'updater']
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
@FieldResolver(type => Domain)
|
|
101
|
-
async domain(@Root() productSet: ProductSet): Promise<Domain> {
|
|
102
|
-
return await getRepository(Domain).findOneBy({ id: productSet.domainId })
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@FieldResolver(type => User)
|
|
106
|
-
async creator(@Root() productSet: ProductSet): Promise<User> {
|
|
107
|
-
return await getRepository(User).findOneBy({ id: productSet.creatorId })
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@FieldResolver(type => User)
|
|
111
|
-
async updater(@Root() productSet: ProductSet): Promise<User> {
|
|
112
|
-
return await getRepository(User).findOneBy({ id: productSet.updaterId })
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { ProductSet } from './product-set'
|
|
4
|
-
|
|
5
|
-
@InputType()
|
|
6
|
-
export class NewProductSet {
|
|
7
|
-
@Field()
|
|
8
|
-
name: string
|
|
9
|
-
|
|
10
|
-
@Field({ nullable: true })
|
|
11
|
-
description?: string
|
|
12
|
-
|
|
13
|
-
@Field({ nullable: true })
|
|
14
|
-
status?: string
|
|
15
|
-
|
|
16
|
-
@Field({ nullable: true })
|
|
17
|
-
type?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@ObjectType()
|
|
21
|
-
export class ProductSetList {
|
|
22
|
-
@Field(type => [ProductSet], { nullable: true })
|
|
23
|
-
items?: ProductSet[]
|
|
24
|
-
|
|
25
|
-
@Field(type => Int, { nullable: true })
|
|
26
|
-
total?: number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@InputType()
|
|
30
|
-
export class ProductSetPatch {
|
|
31
|
-
@Field(type => ID, { nullable: true })
|
|
32
|
-
id?: string
|
|
33
|
-
|
|
34
|
-
@Field({ nullable: true })
|
|
35
|
-
name?: string
|
|
36
|
-
|
|
37
|
-
@Field({ nullable: true })
|
|
38
|
-
description?: string
|
|
39
|
-
|
|
40
|
-
@Field({ nullable: true })
|
|
41
|
-
type?: string
|
|
42
|
-
|
|
43
|
-
@Field({ nullable: true })
|
|
44
|
-
cuFlag?: string
|
|
45
|
-
}
|