@things-factory/code-base 8.0.37 → 9.0.0-9.0.0-beta.59.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-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/client/codes-getter.ts +0 -53
- package/client/index.ts +0 -1
- package/server/index.ts +0 -1
- package/server/service/common-code/common-code-mutation.ts +0 -152
- package/server/service/common-code/common-code-query.ts +0 -74
- package/server/service/common-code/common-code-type.ts +0 -42
- package/server/service/common-code/common-code.ts +0 -73
- package/server/service/common-code/index.ts +0 -6
- package/server/service/common-code-detail/common-code-detail-mutation.ts +0 -153
- package/server/service/common-code-detail/common-code-detail-query.ts +0 -69
- package/server/service/common-code-detail/common-code-detail-type.ts +0 -56
- package/server/service/common-code-detail/common-code-detail.ts +0 -86
- package/server/service/common-code-detail/index.ts +0 -6
- package/server/service/index.ts +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/code-base",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-9.0.0-beta.59.0",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@operato/graphql": "^
|
|
31
|
-
"@things-factory/auth-base": "^
|
|
32
|
-
"@things-factory/shell": "^
|
|
30
|
+
"@operato/graphql": "^9.0.0-beta",
|
|
31
|
+
"@things-factory/auth-base": "^9.0.0-9.0.0-beta.59.0",
|
|
32
|
+
"@things-factory/shell": "^9.0.0-9.0.0-beta.59.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "cf6ee84b991f469a4e71198b0e6314b45e9e10b8"
|
|
35
35
|
}
|
package/client/codes-getter.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { client } from '@operato/graphql'
|
|
2
|
-
import gql from 'graphql-tag'
|
|
3
|
-
|
|
4
|
-
export const getCodeByName = async function (name) {
|
|
5
|
-
if (!name) throw new Error('name is undefined')
|
|
6
|
-
|
|
7
|
-
const response = await client.query({
|
|
8
|
-
query: gql`
|
|
9
|
-
query commonCode($name: String!) {
|
|
10
|
-
commonCode(name: $name) {
|
|
11
|
-
details {
|
|
12
|
-
rank
|
|
13
|
-
name
|
|
14
|
-
description
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`,
|
|
19
|
-
variables: { name }
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
if (!response.errors && response.data.commonCode && response.data.commonCode.details) {
|
|
23
|
-
return response.data.commonCode.details.sort((a, b) => a.rank - b.rank)
|
|
24
|
-
} else {
|
|
25
|
-
return []
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/* TODO move to operato-wms module */
|
|
30
|
-
export const getPartnerCodeByName = async function (name, partnerDomainId) {
|
|
31
|
-
if (!name || !partnerDomainId) throw new Error('parameter is undefined')
|
|
32
|
-
|
|
33
|
-
const response = await client.query({
|
|
34
|
-
query: gql`
|
|
35
|
-
query partnerCommonCode($name: String!, $partnerDomainId: String!) {
|
|
36
|
-
partnerCommonCode(name: $name, partnerDomainId: $partnerDomainId) {
|
|
37
|
-
details {
|
|
38
|
-
rank
|
|
39
|
-
name
|
|
40
|
-
description
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
`,
|
|
45
|
-
variables: { name, partnerDomainId }
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
if (!response.errors && response.data.partnerCommonCode && response.data.partnerCommonCode.details) {
|
|
49
|
-
return response.data.partnerCommonCode.details.sort((a, b) => a.rank - b.rank)
|
|
50
|
-
} else {
|
|
51
|
-
return []
|
|
52
|
-
}
|
|
53
|
-
}
|
package/client/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './codes-getter'
|
package/server/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './service'
|
|
@@ -1,152 +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 { CommonCodeDetail } from '../common-code-detail/common-code-detail'
|
|
7
|
-
import { CommonCode } from './common-code'
|
|
8
|
-
import { CommonCodePatch, NewCommonCode } from './common-code-type'
|
|
9
|
-
|
|
10
|
-
@Resolver(CommonCode)
|
|
11
|
-
export class CommonCodeMutation {
|
|
12
|
-
@Directive('@transaction')
|
|
13
|
-
@Mutation(returns => CommonCode, { description: 'To create new CommonCode' })
|
|
14
|
-
async createCommonCode(
|
|
15
|
-
@Arg('commonCode') commonCode: NewCommonCode,
|
|
16
|
-
@Ctx() context: ResolverContext
|
|
17
|
-
): Promise<CommonCode> {
|
|
18
|
-
const { domain, user, tx } = context.state
|
|
19
|
-
|
|
20
|
-
const details = await getRepository(CommonCodeDetail).findByIds(commonCode.details || [])
|
|
21
|
-
|
|
22
|
-
return await tx.getRepository(CommonCode).save({
|
|
23
|
-
...commonCode,
|
|
24
|
-
details,
|
|
25
|
-
domain,
|
|
26
|
-
creator: user,
|
|
27
|
-
updater: user
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Directive('@transaction')
|
|
32
|
-
@Mutation(returns => CommonCode, { description: 'To modify CommonCode information' })
|
|
33
|
-
async updateCommonCode(
|
|
34
|
-
@Arg('name') name: string,
|
|
35
|
-
@Arg('patch') patch: CommonCodePatch,
|
|
36
|
-
@Ctx() context: ResolverContext
|
|
37
|
-
): Promise<CommonCode> {
|
|
38
|
-
const { domain, user, tx } = context.state
|
|
39
|
-
|
|
40
|
-
const repository = tx.getRepository(CommonCode)
|
|
41
|
-
const commonCode = await repository.findOne({
|
|
42
|
-
where: { domain: { id: domain.id }, name },
|
|
43
|
-
relations: ['details']
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const detailIds = commonCode.details.map(detail => detail.id)
|
|
47
|
-
if (patch.details && patch.details.length) {
|
|
48
|
-
patch.details.forEach((detailId: string) => {
|
|
49
|
-
if (!detailIds.includes(detailId)) {
|
|
50
|
-
detailIds.push(detailId)
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return await repository.save({
|
|
56
|
-
...commonCode,
|
|
57
|
-
...patch,
|
|
58
|
-
details: await getRepository(CommonCodeDetail).findByIds(detailIds),
|
|
59
|
-
updater: user
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Directive('@transaction')
|
|
64
|
-
@Mutation(returns => [CommonCode], { description: "To modify multiple CommonCodes' information" })
|
|
65
|
-
async updateMultipleCommonCode(
|
|
66
|
-
@Arg('patches', type => [CommonCodePatch]) patches: CommonCodePatch[],
|
|
67
|
-
@Ctx() context: ResolverContext
|
|
68
|
-
): Promise<CommonCode[]> {
|
|
69
|
-
const { domain, user, tx } = context.state
|
|
70
|
-
|
|
71
|
-
let results = []
|
|
72
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
73
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
74
|
-
const commonCodeRepo = tx.getRepository(CommonCode)
|
|
75
|
-
|
|
76
|
-
if (_createRecords.length > 0) {
|
|
77
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
78
|
-
const newRecord = _createRecords[i]
|
|
79
|
-
|
|
80
|
-
const result = await commonCodeRepo.save({
|
|
81
|
-
...(newRecord as any),
|
|
82
|
-
domain,
|
|
83
|
-
creator: user,
|
|
84
|
-
updater: user
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
results.push({ ...result, cuFlag: '+' })
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (_updateRecords.length > 0) {
|
|
92
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
93
|
-
const newRecord = _updateRecords[i]
|
|
94
|
-
const commonCode = await commonCodeRepo.findOneBy({ id: newRecord.id })
|
|
95
|
-
|
|
96
|
-
const result = await commonCodeRepo.save({
|
|
97
|
-
...commonCode,
|
|
98
|
-
...(newRecord as any),
|
|
99
|
-
updater: user
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return results
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Directive('@transaction')
|
|
110
|
-
@Mutation(returns => Boolean, { description: 'To delete CommonCode' })
|
|
111
|
-
async deleteCommonCode(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
112
|
-
const { domain, tx } = context.state
|
|
113
|
-
|
|
114
|
-
await tx.getRepository(CommonCode).delete({ domain: { id: domain.id }, id })
|
|
115
|
-
return true
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@Directive('@transaction')
|
|
119
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple CommonCodes' })
|
|
120
|
-
async deleteCommonCodes(
|
|
121
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
122
|
-
@Ctx() context: ResolverContext
|
|
123
|
-
): Promise<boolean> {
|
|
124
|
-
const { domain, tx } = context.state
|
|
125
|
-
|
|
126
|
-
await tx.getRepository(CommonCode).delete({
|
|
127
|
-
domain: { id: domain.id },
|
|
128
|
-
id: In(ids)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
return true
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@Directive('@transaction')
|
|
135
|
-
@Mutation(returns => Boolean, { description: 'To import multiple CommonCodes' })
|
|
136
|
-
async importCommonCodes(
|
|
137
|
-
@Arg('commonCodes', type => [CommonCodePatch]) commonCodes: CommonCodePatch[],
|
|
138
|
-
@Ctx() context: ResolverContext
|
|
139
|
-
): Promise<boolean> {
|
|
140
|
-
const { domain, tx } = context.state
|
|
141
|
-
|
|
142
|
-
await Promise.all(
|
|
143
|
-
commonCodes.map(async (commonCode: CommonCodePatch) => {
|
|
144
|
-
const createdCommonCode: CommonCode = await tx
|
|
145
|
-
.getRepository(CommonCode)
|
|
146
|
-
.save({ domain, ...(commonCode as any) })
|
|
147
|
-
})
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
return true
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
6
|
-
|
|
7
|
-
import { CommonCodeDetail } from '../common-code-detail/common-code-detail'
|
|
8
|
-
import { CommonCode } from './common-code'
|
|
9
|
-
import { CommonCodeList } from './common-code-type'
|
|
10
|
-
|
|
11
|
-
@Resolver(CommonCode)
|
|
12
|
-
export class CommonCodeQuery {
|
|
13
|
-
@Query(returns => CommonCode!, { nullable: true, description: 'To fetch a CommonCode' })
|
|
14
|
-
async commonCode(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<CommonCode> {
|
|
15
|
-
const { domain } = context.state
|
|
16
|
-
|
|
17
|
-
return await getRepository(CommonCode).findOne({
|
|
18
|
-
where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, name }
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Query(returns => CommonCodeList, { description: 'To fetch multiple CommonCodes' })
|
|
23
|
-
async commonCodes(
|
|
24
|
-
@Args(type => ListParam) params: ListParam,
|
|
25
|
-
@Ctx() context: ResolverContext
|
|
26
|
-
): Promise<CommonCodeList> {
|
|
27
|
-
const { domain } = context.state
|
|
28
|
-
|
|
29
|
-
const queryBuilder = getQueryBuilderFromListParams({
|
|
30
|
-
domain,
|
|
31
|
-
params,
|
|
32
|
-
repository: await getRepository(CommonCode),
|
|
33
|
-
searchables: ['name', 'description']
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
37
|
-
|
|
38
|
-
return { items, total }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/* TODO move to operato-wms module */
|
|
42
|
-
@Query(returns => CommonCode, { description: "To fetch specific domain's CommonCodes by given name" })
|
|
43
|
-
async partnerCommonCode(
|
|
44
|
-
@Arg('name') name: string,
|
|
45
|
-
@Arg('partnerDomainId') partnerDomainId: string,
|
|
46
|
-
@Ctx() context: ResolverContext
|
|
47
|
-
): Promise<CommonCode> {
|
|
48
|
-
return await getRepository(CommonCode).findOne({
|
|
49
|
-
where: { domain: { id: partnerDomainId }, name }
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@FieldResolver(type => [CommonCodeDetail])
|
|
54
|
-
async details(@Root() commonCode: CommonCode): Promise<CommonCodeDetail[]> {
|
|
55
|
-
return await getRepository(CommonCodeDetail).findBy({
|
|
56
|
-
commonCode: { id: commonCode.id }
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@FieldResolver(type => Domain)
|
|
61
|
-
async domain(@Root() commonCode: CommonCode): Promise<Domain> {
|
|
62
|
-
return await getRepository(Domain).findOneBy({ id: commonCode.domainId })
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@FieldResolver(type => User)
|
|
66
|
-
async updater(@Root() commonCode: CommonCode): Promise<User> {
|
|
67
|
-
return await getRepository(User).findOneBy({ id: commonCode.updaterId })
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@FieldResolver(type => User)
|
|
71
|
-
async creator(@Root() commonCode: CommonCode): Promise<User> {
|
|
72
|
-
return await getRepository(User).findOneBy({ id: commonCode.creatorId })
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
-
|
|
3
|
-
import { CommonCode } from './common-code'
|
|
4
|
-
|
|
5
|
-
@InputType()
|
|
6
|
-
export class NewCommonCode {
|
|
7
|
-
@Field()
|
|
8
|
-
name: string
|
|
9
|
-
|
|
10
|
-
@Field({ nullable: true })
|
|
11
|
-
description?: string
|
|
12
|
-
|
|
13
|
-
@Field(type => [String], { nullable: true })
|
|
14
|
-
details?: string[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@InputType()
|
|
18
|
-
export class CommonCodePatch {
|
|
19
|
-
@Field(type => ID, { nullable: true })
|
|
20
|
-
id?: string
|
|
21
|
-
|
|
22
|
-
@Field({ nullable: true })
|
|
23
|
-
name?: string
|
|
24
|
-
|
|
25
|
-
@Field({ nullable: true })
|
|
26
|
-
description?: string
|
|
27
|
-
|
|
28
|
-
@Field(type => [String], { nullable: true })
|
|
29
|
-
details?: string[]
|
|
30
|
-
|
|
31
|
-
@Field({ nullable: true })
|
|
32
|
-
cuFlag?: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@ObjectType()
|
|
36
|
-
export class CommonCodeList {
|
|
37
|
-
@Field(type => [CommonCode])
|
|
38
|
-
items: CommonCode[]
|
|
39
|
-
|
|
40
|
-
@Field(type => Int)
|
|
41
|
-
total: number
|
|
42
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Field, ID, ObjectType } 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 { CommonCodeDetail } from '../common-code-detail/common-code-detail'
|
|
18
|
-
|
|
19
|
-
@Entity()
|
|
20
|
-
@Index('ix_common_code_0', (commonCode: CommonCode) => [commonCode.domain, commonCode.name], { unique: true })
|
|
21
|
-
@Index('ix_common_code_1', (commonCode: CommonCode) => [commonCode.domain]) /* TOBE-REMOVED */
|
|
22
|
-
@ObjectType({ description: 'Entity for CommonCode' })
|
|
23
|
-
export class CommonCode {
|
|
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((commonCode: CommonCode) => commonCode.domain)
|
|
33
|
-
domainId?: string
|
|
34
|
-
|
|
35
|
-
@Column()
|
|
36
|
-
@Field()
|
|
37
|
-
name: string
|
|
38
|
-
|
|
39
|
-
@Column({
|
|
40
|
-
nullable: true
|
|
41
|
-
})
|
|
42
|
-
@Field({ nullable: true })
|
|
43
|
-
description?: string
|
|
44
|
-
|
|
45
|
-
@OneToMany(type => CommonCodeDetail, commonCodeDetail => commonCodeDetail.commonCode)
|
|
46
|
-
details: CommonCodeDetail[]
|
|
47
|
-
|
|
48
|
-
@CreateDateColumn()
|
|
49
|
-
@Field({ nullable: true })
|
|
50
|
-
createdAt?: Date
|
|
51
|
-
|
|
52
|
-
@UpdateDateColumn()
|
|
53
|
-
@Field({ nullable: true })
|
|
54
|
-
updatedAt?: Date
|
|
55
|
-
|
|
56
|
-
@ManyToOne(type => User, {
|
|
57
|
-
nullable: true
|
|
58
|
-
})
|
|
59
|
-
@Field(type => User, { nullable: true })
|
|
60
|
-
creator?: User
|
|
61
|
-
|
|
62
|
-
@RelationId((commonCode: CommonCode) => commonCode.creator)
|
|
63
|
-
creatorId?: string
|
|
64
|
-
|
|
65
|
-
@ManyToOne(type => User, {
|
|
66
|
-
nullable: true
|
|
67
|
-
})
|
|
68
|
-
@Field(type => User, { nullable: true })
|
|
69
|
-
updater?: User
|
|
70
|
-
|
|
71
|
-
@RelationId((commonCode: CommonCode) => commonCode.updater)
|
|
72
|
-
updaterId?: string
|
|
73
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { CommonCode } from '../common-code/common-code'
|
|
5
|
-
import { CommonCodeDetail } from './common-code-detail'
|
|
6
|
-
import { CommonCodeDetailPatch, NewCommonCodeDetail } from './common-code-detail-type'
|
|
7
|
-
|
|
8
|
-
@Resolver(CommonCodeDetail)
|
|
9
|
-
export class CommonCodeDetailMutation {
|
|
10
|
-
@Directive('@transaction')
|
|
11
|
-
@Mutation(returns => CommonCodeDetail, { description: 'To create new CommonCodeDetail' })
|
|
12
|
-
async createCommonCodeDetail(
|
|
13
|
-
@Arg('commonCodeDetail') commonCodeDetail: NewCommonCodeDetail,
|
|
14
|
-
@Ctx() context: ResolverContext
|
|
15
|
-
): Promise<CommonCodeDetail> {
|
|
16
|
-
const { domain, user, tx } = context.state
|
|
17
|
-
|
|
18
|
-
if (commonCodeDetail && commonCodeDetail.commonCode.id) {
|
|
19
|
-
commonCodeDetail.commonCode = await tx.getRepository(CommonCode).findOneBy({ id: commonCodeDetail.commonCode.id })
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return await tx.getRepository(CommonCodeDetail).save({
|
|
23
|
-
...commonCodeDetail,
|
|
24
|
-
domain,
|
|
25
|
-
creator: user,
|
|
26
|
-
updater: user
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@Directive('@transaction')
|
|
31
|
-
@Mutation(returns => CommonCodeDetail, { description: 'To modify CommonCodeDetail information' })
|
|
32
|
-
async updateCommonCodeDetail(
|
|
33
|
-
@Arg('id') id: string,
|
|
34
|
-
@Arg('patch') patch: CommonCodeDetailPatch,
|
|
35
|
-
@Ctx() context: ResolverContext
|
|
36
|
-
): Promise<CommonCodeDetail> {
|
|
37
|
-
const { domain, user, tx } = context.state
|
|
38
|
-
|
|
39
|
-
const repository = tx.getRepository(CommonCodeDetail)
|
|
40
|
-
const commonCodeDetail = await repository.findOne({
|
|
41
|
-
where: { domain: { id: domain.id }, id }
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
if (patch.commonCode && patch.commonCode.id) {
|
|
45
|
-
patch.commonCode = await tx.getRepository(CommonCode).findOneBy({ id: patch.commonCode.id })
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return await repository.save({
|
|
49
|
-
...commonCodeDetail,
|
|
50
|
-
...patch,
|
|
51
|
-
updater: user
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@Directive('@transaction')
|
|
56
|
-
@Mutation(returns => [CommonCodeDetail], { description: "To modify multiple CommonCodeDetails' information" })
|
|
57
|
-
async updateMultipleCommonCodeDetail(
|
|
58
|
-
@Arg('patches', type => [CommonCodeDetailPatch]) patches: CommonCodeDetailPatch[],
|
|
59
|
-
@Ctx() context: ResolverContext
|
|
60
|
-
): Promise<CommonCodeDetail[]> {
|
|
61
|
-
const { domain, user, tx } = context.state
|
|
62
|
-
|
|
63
|
-
let results = []
|
|
64
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
65
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
66
|
-
const commonCodeRepo = tx.getRepository(CommonCode)
|
|
67
|
-
const commonCodeDetailRepo = tx.getRepository(CommonCodeDetail)
|
|
68
|
-
|
|
69
|
-
if (_createRecords.length > 0) {
|
|
70
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
71
|
-
const newRecord = _createRecords[i]
|
|
72
|
-
|
|
73
|
-
if (newRecord.commonCode && newRecord.commonCode.id) {
|
|
74
|
-
newRecord.commonCode = await commonCodeRepo.findOneBy({ id: newRecord.commonCode.id })
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const result = await commonCodeDetailRepo.save({
|
|
78
|
-
...newRecord,
|
|
79
|
-
domain,
|
|
80
|
-
creator: user,
|
|
81
|
-
updater: user
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
results.push({ ...result, cuFlag: '+' })
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (_updateRecords.length > 0) {
|
|
89
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
90
|
-
const newRecord = _updateRecords[i]
|
|
91
|
-
const commonCodeDetail = await commonCodeDetailRepo.findOneBy({ id: newRecord.id })
|
|
92
|
-
|
|
93
|
-
if (newRecord.commonCode && newRecord.commonCode.id) {
|
|
94
|
-
newRecord.commonCode = await commonCodeRepo.findOneBy({ id: newRecord.commonCode.id })
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const result = await commonCodeDetailRepo.save({
|
|
98
|
-
...commonCodeDetail,
|
|
99
|
-
...newRecord,
|
|
100
|
-
updater: user
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return results
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@Directive('@transaction')
|
|
111
|
-
@Mutation(returns => Boolean, { description: 'To delete CommonCodeDetail' })
|
|
112
|
-
async deleteCommonCodeDetail(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
113
|
-
const { domain, tx } = context.state
|
|
114
|
-
|
|
115
|
-
await tx.getRepository(CommonCodeDetail).delete({ domain: { id: domain.id }, id })
|
|
116
|
-
return true
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@Directive('@transaction')
|
|
120
|
-
@Mutation(returns => Boolean, { description: 'To delete multiple CommonCodeDetails' })
|
|
121
|
-
async deleteCommonCodeDetails(
|
|
122
|
-
@Arg('ids', type => [String]) ids: string[],
|
|
123
|
-
@Ctx() context: ResolverContext
|
|
124
|
-
): Promise<boolean> {
|
|
125
|
-
const { domain, tx } = context.state
|
|
126
|
-
|
|
127
|
-
await tx.getRepository(CommonCodeDetail).delete({
|
|
128
|
-
domain: { id: domain.id },
|
|
129
|
-
id: In(ids)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
return true
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@Directive('@transaction')
|
|
136
|
-
@Mutation(returns => Boolean, { description: 'To import multiple CommonCodeDetails' })
|
|
137
|
-
async importCommonCodeDetails(
|
|
138
|
-
@Arg('commonCodeDetails', type => [CommonCodeDetailPatch]) commonCodeDetails: CommonCodeDetailPatch[],
|
|
139
|
-
@Ctx() context: ResolverContext
|
|
140
|
-
): Promise<boolean> {
|
|
141
|
-
const { domain, tx } = context.state
|
|
142
|
-
|
|
143
|
-
await Promise.all(
|
|
144
|
-
commonCodeDetails.map(async (commonCodeDetail: CommonCodeDetailPatch) => {
|
|
145
|
-
const createdCommonCodeDetail: CommonCodeDetail = await tx
|
|
146
|
-
.getRepository(CommonCodeDetail)
|
|
147
|
-
.save({ domain, ...commonCodeDetail })
|
|
148
|
-
})
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
return true
|
|
152
|
-
}
|
|
153
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { In } from 'typeorm'
|
|
3
|
-
|
|
4
|
-
import { User } from '@things-factory/auth-base'
|
|
5
|
-
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
6
|
-
|
|
7
|
-
import { CommonCode } from '../common-code/common-code'
|
|
8
|
-
import { CommonCodeDetail } from './common-code-detail'
|
|
9
|
-
import { CommonCodeDetailList } from './common-code-detail-type'
|
|
10
|
-
|
|
11
|
-
@Resolver(CommonCodeDetail)
|
|
12
|
-
export class CommonCodeDetailQuery {
|
|
13
|
-
@Query(returns => CommonCodeDetail, { description: 'To fetch a CommonCodeDetail' })
|
|
14
|
-
async commonCodeDetail(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<CommonCodeDetail> {
|
|
15
|
-
const { domain } = context.state
|
|
16
|
-
|
|
17
|
-
return await getRepository(CommonCodeDetail).findOne({
|
|
18
|
-
where: { domain: { id: In([domain.id, domain.parentId].filter(Boolean)) }, id }
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Query(returns => CommonCodeDetailList, { description: 'To fetch multiple CommonCodeDetails' })
|
|
23
|
-
async commonCodeDetails(
|
|
24
|
-
@Args(type => ListParam) params: ListParam,
|
|
25
|
-
@Ctx() context: ResolverContext
|
|
26
|
-
): Promise<CommonCodeDetailList> {
|
|
27
|
-
const { domain } = context.state
|
|
28
|
-
|
|
29
|
-
const queryBuilder = getQueryBuilderFromListParams({
|
|
30
|
-
domain,
|
|
31
|
-
params,
|
|
32
|
-
repository: await getRepository(CommonCodeDetail),
|
|
33
|
-
alias: 'ccd',
|
|
34
|
-
searchables: ['name', 'description']
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const [items, total] = await queryBuilder.getManyAndCount()
|
|
38
|
-
|
|
39
|
-
return { items, total }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@FieldResolver(type => String)
|
|
43
|
-
async commonCode(commonCodeDetail): Promise<CommonCode> {
|
|
44
|
-
return await getRepository(CommonCode).findOneBy({ id: commonCodeDetail.commonCodeId })
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@FieldResolver(type => Domain)
|
|
48
|
-
async description(@Root() commonCodeDetail: CommonCodeDetail, @Ctx() context: ResolverContext): Promise<String> {
|
|
49
|
-
const { lng } = context.state
|
|
50
|
-
const { labels, description } = commonCodeDetail
|
|
51
|
-
|
|
52
|
-
return (lng && labels && labels[lng]) || description
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@FieldResolver(type => Domain)
|
|
56
|
-
async domain(@Root() commonCodeDetail: CommonCodeDetail): Promise<Domain> {
|
|
57
|
-
return await getRepository(Domain).findOneBy({ id: commonCodeDetail.domainId })
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@FieldResolver(type => User)
|
|
61
|
-
async updater(@Root() commonCodeDetail: CommonCodeDetail): Promise<User> {
|
|
62
|
-
return await getRepository(User).findOneBy({ id: commonCodeDetail.updaterId })
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@FieldResolver(type => User)
|
|
66
|
-
async creator(@Root() commonCodeDetail: CommonCodeDetail): Promise<User> {
|
|
67
|
-
return await getRepository(User).findOneBy({ id: commonCodeDetail.creatorId })
|
|
68
|
-
}
|
|
69
|
-
}
|