@things-factory/meta-ui 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/client/bootstrap.ts +170 -0
- package/client/component/filter/filter-form-meta-code-select.ts +102 -0
- package/client/component/filter/filter-form-meta-object-select.ts +107 -0
- package/client/component/filter/filter-grist-meta-code-select.ts +97 -0
- package/client/component/filter/filter-grist-meta-object-select.ts +102 -0
- package/client/component/grist/editor/grist-editor-code-input.js +96 -0
- package/client/component/grist/editor/grist-editor-meta-code-selector.js +157 -0
- package/client/component/grist/editor/grist-editor-meta-object-selector.js +122 -0
- package/client/component/grist/renderer/grist-renderer-code-input.js +20 -0
- package/client/component/grist/renderer/grist-renderer-meta-code-selector.js +28 -0
- package/client/component/grist/renderer/grist-renderer-meta-object-selector.js +25 -0
- package/client/component/popup/code-input-editor-popup.js +111 -0
- package/client/component/popup/file-upload-popup.js +129 -0
- package/client/component/popup/meta-object-selector-popup.ts +356 -0
- package/client/component/popup/record-based-code-editor-popup.ts +141 -0
- package/client/dynamic-menus.ts +38 -0
- package/client/index.ts +18 -0
- package/client/load-components.ts +17 -0
- package/client/mixin/meta-base-mixin.js +323 -0
- package/client/mixin/meta-basic-grist-mixin.js +283 -0
- package/client/mixin/meta-button-mixin.js +116 -0
- package/client/mixin/meta-form-mixin.js +435 -0
- package/client/mixin/meta-grist-tab-mixin.js +335 -0
- package/client/mixin/meta-main-tab-mixin.js +267 -0
- package/client/mixin/meta-master-detail-mixin.js +395 -0
- package/client/mixin/meta-service-mixin.js +306 -0
- package/client/mixin/meta-tab-detail-mixin.js +283 -0
- package/client/mixin/meta-tab-mixin.js +190 -0
- package/client/pages/activity/meta-activity-define-page.js +422 -0
- package/client/pages/activity/meta-activity-list-page.js +262 -0
- package/client/pages/activity/meta-activity-viewer-element.js +35 -0
- package/client/pages/activity/meta-activity-writer-element.js +48 -0
- package/client/pages/activity/meta-activiy-mixin.js +79 -0
- package/client/pages/button-role/button-role-detail.js +50 -0
- package/client/pages/button-role/button-role-page.js +25 -0
- package/client/pages/doc-number/doc-number-page.js +24 -0
- package/client/pages/doc-number/next-doc-number-popup.js +25 -0
- package/client/pages/entity/config-entity.js +955 -0
- package/client/pages/entity/main-menu-selector.js +245 -0
- package/client/pages/history/history-copy-list-popup.js +145 -0
- package/client/pages/history/history-json-list-popup.js +159 -0
- package/client/pages/menu/dynamic-menu-template.js +92 -0
- package/client/pages/menu/dynamic-menu.ts +744 -0
- package/client/pages/menu/export-menu-popup.js +468 -0
- package/client/pages/meta-form-element.js +9 -0
- package/client/pages/meta-grist-element.js +12 -0
- package/client/pages/meta-grist-page.js +16 -0
- package/client/pages/meta-grist-tab-element.js +16 -0
- package/client/pages/meta-grist-tab-page.js +16 -0
- package/client/pages/meta-main-tab-element.js +12 -0
- package/client/pages/meta-main-tab-page.js +16 -0
- package/client/pages/meta-master-detail-element.js +12 -0
- package/client/pages/meta-master-detail-page.js +16 -0
- package/client/pages/meta-tab-detail-element.js +12 -0
- package/client/pages/meta-tab-detail-page.js +16 -0
- package/client/pages/meta-tab-element.js +15 -0
- package/client/pages/printer-device/printer-device-page.js +24 -0
- package/client/pages/template/doc-template-page.js +24 -0
- package/client/pages/template/template-file-page.js +24 -0
- package/client/pages/terms/config-terminology.js +214 -0
- package/client/pages/work-code/work-code-detail-popup.js +16 -0
- package/client/pages/work-code/work-code-page.js +23 -0
- package/client/route.ts +36 -0
- package/client/tsconfig.json +13 -0
- package/client/utils/grist-default-value.js +36 -0
- package/client/utils/meta-api.js +811 -0
- package/client/utils/meta-crypto.js +52 -0
- package/client/utils/meta-ui-util.js +3304 -0
- package/client/utils/rest-service-util.js +328 -0
- package/client/utils/service-util.js +1327 -0
- package/client/utils/terms-util.ts +119 -0
- package/client/utils/ui-util.js +338 -0
- package/client/utils/value-util.js +234 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-client/utils/service-util.d.ts +2 -2
- package/dist-client/utils/service-util.js +4 -4
- package/dist-client/utils/service-util.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -24
- package/server/activity/CommonActivity.ts +68 -0
- package/server/index.ts +3 -0
- package/server/routes.ts +61 -0
- package/server/service/button-role/button-role-mutation.ts +105 -0
- package/server/service/button-role/button-role-query.ts +53 -0
- package/server/service/button-role/button-role-type.ts +39 -0
- package/server/service/button-role/button-role.ts +61 -0
- package/server/service/button-role/index.ts +7 -0
- package/server/service/dynamic-menu/dynamic-menu-query.ts +270 -0
- package/server/service/dynamic-menu/dynamic-menu-type.ts +74 -0
- package/server/service/dynamic-menu/index.ts +3 -0
- package/server/service/entity-event-subscriber/entity-event-subscriber.ts +80 -0
- package/server/service/entity-event-subscriber/index.ts +3 -0
- package/server/service/index.ts +41 -0
- package/server/service/menu-button-auth/index.ts +7 -0
- package/server/service/menu-button-auth/menu-button-auth-mutation.ts +133 -0
- package/server/service/menu-button-auth/menu-button-auth-query.ts +138 -0
- package/server/service/menu-button-auth/menu-button-auth-type.ts +63 -0
- package/server/service/menu-button-auth/menu-button-auth.ts +92 -0
- package/server/service/meta-activity/index.ts +5 -0
- package/server/service/meta-activity/meta-activity-mutation.ts +191 -0
- package/server/service/meta-activity/meta-activity-query.ts +43 -0
- package/server/service/meta-activity/meta-activity-type.ts +56 -0
- package/server/service/set-translations/index.ts +3 -0
- package/server/service/set-translations/set-translation-resolver.ts +63 -0
- package/server/service/work-code/index.ts +6 -0
- package/server/service/work-code/work-code-mutation.ts +147 -0
- package/server/service/work-code/work-code-query.ts +67 -0
- package/server/service/work-code/work-code-type.ts +60 -0
- package/server/service/work-code/work-code.ts +83 -0
- package/server/service/work-code-detail/index.ts +6 -0
- package/server/service/work-code-detail/work-code-detail-mutation.ts +149 -0
- package/server/service/work-code-detail/work-code-detail-query.ts +59 -0
- package/server/service/work-code-detail/work-code-detail-type.ts +50 -0
- package/server/service/work-code-detail/work-code-detail.ts +82 -0
- package/server/tsconfig.json +9 -0
|
@@ -0,0 +1,147 @@
|
|
|
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 { WorkCodeDetail } from '../work-code-detail/work-code-detail'
|
|
7
|
+
import { WorkCode } from './work-code'
|
|
8
|
+
import { WorkCodePatch, NewWorkCode } from './work-code-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(WorkCode)
|
|
11
|
+
export class WorkCodeMutation {
|
|
12
|
+
@Directive('@transaction')
|
|
13
|
+
@Mutation(returns => WorkCode, { description: 'To create new WorkCode' })
|
|
14
|
+
async createWorkCode(
|
|
15
|
+
@Arg('workCode') workCode: NewWorkCode,
|
|
16
|
+
@Ctx() context: ResolverContext
|
|
17
|
+
): Promise<WorkCode> {
|
|
18
|
+
const { domain, user, tx } = context.state
|
|
19
|
+
|
|
20
|
+
const details = await getRepository(WorkCodeDetail).findByIds(workCode.details || [])
|
|
21
|
+
|
|
22
|
+
return await tx.getRepository(WorkCode).save({
|
|
23
|
+
...workCode,
|
|
24
|
+
details,
|
|
25
|
+
domain,
|
|
26
|
+
creator: user,
|
|
27
|
+
updater: user
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Directive('@transaction')
|
|
32
|
+
@Mutation(returns => WorkCode, { description: 'To modify WorkCode information' })
|
|
33
|
+
async updateWorkCode(
|
|
34
|
+
@Arg('patch') patch: WorkCodePatch,
|
|
35
|
+
@Ctx() context: ResolverContext
|
|
36
|
+
): Promise<WorkCode> {
|
|
37
|
+
const { domain, user, tx } = context.state
|
|
38
|
+
|
|
39
|
+
const repository = tx.getRepository(WorkCode)
|
|
40
|
+
const workCode = await repository.findOne({
|
|
41
|
+
where: { id:patch.id },
|
|
42
|
+
relations: ['details']
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const detailIds = workCode.details.map(detail => detail.id)
|
|
46
|
+
if (patch.details && patch.details.length) {
|
|
47
|
+
patch.details.forEach((detailId: string) => {
|
|
48
|
+
if (!detailIds.includes(detailId)) {
|
|
49
|
+
detailIds.push(detailId)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return await repository.save({
|
|
55
|
+
...workCode,
|
|
56
|
+
...patch,
|
|
57
|
+
details: await getRepository(WorkCodeDetail).findByIds(detailIds),
|
|
58
|
+
updater: user
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Directive('@transaction')
|
|
63
|
+
@Mutation(returns => [WorkCode], { description: "To modify multiple WorkCodes' information" })
|
|
64
|
+
async updateMultipleWorkCode(
|
|
65
|
+
@Arg('patches', type => [WorkCodePatch]) patches: WorkCodePatch[],
|
|
66
|
+
@Ctx() context: ResolverContext
|
|
67
|
+
): Promise<WorkCode[]> {
|
|
68
|
+
const { domain, user, tx } = context.state
|
|
69
|
+
|
|
70
|
+
let results = []
|
|
71
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
72
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
73
|
+
const commonCodeRepo = tx.getRepository(WorkCode)
|
|
74
|
+
|
|
75
|
+
if (_createRecords.length > 0) {
|
|
76
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
77
|
+
const newRecord = _createRecords[i]
|
|
78
|
+
|
|
79
|
+
const result = await commonCodeRepo.save({
|
|
80
|
+
...(newRecord as any),
|
|
81
|
+
domain,
|
|
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 commonCode = await commonCodeRepo.findOneBy({ id: newRecord.id })
|
|
94
|
+
|
|
95
|
+
const result = await commonCodeRepo.save({
|
|
96
|
+
...commonCode,
|
|
97
|
+
...(newRecord as any),
|
|
98
|
+
updater: user
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return results
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Directive('@transaction')
|
|
109
|
+
@Mutation(returns => Boolean, { description: 'To delete WorkCode' })
|
|
110
|
+
async deleteWorkCode(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
111
|
+
const { domain, tx } = context.state
|
|
112
|
+
|
|
113
|
+
await tx.getRepository(WorkCode).delete({ id })
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Directive('@transaction')
|
|
118
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple WorkCodes' })
|
|
119
|
+
async deleteWorkCodes(
|
|
120
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
121
|
+
@Ctx() context: ResolverContext
|
|
122
|
+
): Promise<boolean> {
|
|
123
|
+
const { domain, tx } = context.state
|
|
124
|
+
|
|
125
|
+
await tx.getRepository(WorkCode).delete({id: In(ids)})
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Directive('@transaction')
|
|
130
|
+
@Mutation(returns => Boolean, { description: 'To import multiple WorkCodes' })
|
|
131
|
+
async importWorkCodes(
|
|
132
|
+
@Arg('workCodes', type => [WorkCodePatch]) commonCodes: WorkCodePatch[],
|
|
133
|
+
@Ctx() context: ResolverContext
|
|
134
|
+
): Promise<boolean> {
|
|
135
|
+
const { domain, tx } = context.state
|
|
136
|
+
|
|
137
|
+
await Promise.all(
|
|
138
|
+
commonCodes.map(async (workCode: WorkCodePatch) => {
|
|
139
|
+
const createdWorkCode: WorkCode = await tx
|
|
140
|
+
.getRepository(WorkCode)
|
|
141
|
+
.save({ domain, ...(workCode as any) })
|
|
142
|
+
})
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
return true
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { WorkCodeDetail } from '../work-code-detail/work-code-detail'
|
|
7
|
+
import { WorkCode } from './work-code'
|
|
8
|
+
import { WorkCodeList } from './work-code-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(WorkCode)
|
|
11
|
+
export class WorkCodeQuery {
|
|
12
|
+
@Query(returns => WorkCode!, { nullable: true, description: 'To fetch a WorkCode' })
|
|
13
|
+
async workCode(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<WorkCode> {
|
|
14
|
+
const { domain } = context.state
|
|
15
|
+
|
|
16
|
+
return await getRepository(WorkCode).findOne({
|
|
17
|
+
where: { id }
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Query(returns => WorkCode!, { nullable: true, description: 'To fetch a WorkCode' })
|
|
22
|
+
async workCodeByName(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<WorkCode> {
|
|
23
|
+
const { domain } = context.state
|
|
24
|
+
|
|
25
|
+
return await getRepository(WorkCode).findOne({
|
|
26
|
+
where: { domain: { id: domain.id }, name }
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Query(returns => WorkCodeList, { description: 'To fetch multiple WorkCodes' })
|
|
31
|
+
async workCodes(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<WorkCodeList> {
|
|
32
|
+
const { domain } = context.state
|
|
33
|
+
|
|
34
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
35
|
+
domain,
|
|
36
|
+
params,
|
|
37
|
+
repository: await getRepository(WorkCode),
|
|
38
|
+
searchables: ['name', 'description']
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
42
|
+
|
|
43
|
+
return { items, total }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@FieldResolver(type => [WorkCodeDetail])
|
|
47
|
+
async details(@Root() workCode: WorkCode): Promise<WorkCodeDetail[]> {
|
|
48
|
+
return await getRepository(WorkCodeDetail).findBy({
|
|
49
|
+
workCode: { id: workCode.id }
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@FieldResolver(type => Domain)
|
|
54
|
+
async domain(@Root() workCode: WorkCode): Promise<Domain> {
|
|
55
|
+
return await getRepository(Domain).findOneBy({ id: workCode.domainId })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@FieldResolver(type => User)
|
|
59
|
+
async updater(@Root() workCode: WorkCode): Promise<User> {
|
|
60
|
+
return await getRepository(User).findOneBy({ id: workCode.updaterId })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@FieldResolver(type => User)
|
|
64
|
+
async creator(@Root() workCode: WorkCode): Promise<User> {
|
|
65
|
+
return await getRepository(User).findOneBy({ id: workCode.creatorId })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { WorkCode } from './work-code'
|
|
4
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
export class NewWorkCode {
|
|
7
|
+
@Field()
|
|
8
|
+
name: string
|
|
9
|
+
|
|
10
|
+
@Field({ nullable: true })
|
|
11
|
+
description?: string
|
|
12
|
+
|
|
13
|
+
@Field({ nullable: true })
|
|
14
|
+
category1?: string
|
|
15
|
+
|
|
16
|
+
@Field({ nullable: true })
|
|
17
|
+
category2?: string
|
|
18
|
+
|
|
19
|
+
@Field({ nullable: true })
|
|
20
|
+
category3?: string
|
|
21
|
+
|
|
22
|
+
@Field(type => [String], { nullable: true })
|
|
23
|
+
details?: string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@InputType()
|
|
27
|
+
export class WorkCodePatch {
|
|
28
|
+
@Field(type => ID, { nullable: true })
|
|
29
|
+
id?: string
|
|
30
|
+
|
|
31
|
+
@Field({ nullable: true })
|
|
32
|
+
name?: string
|
|
33
|
+
|
|
34
|
+
@Field({ nullable: true })
|
|
35
|
+
description?: string
|
|
36
|
+
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
category1?: string
|
|
39
|
+
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
category2?: string
|
|
42
|
+
|
|
43
|
+
@Field({ nullable: true })
|
|
44
|
+
category3?: string
|
|
45
|
+
|
|
46
|
+
@Field(type => [String], { nullable: true })
|
|
47
|
+
details?: string[]
|
|
48
|
+
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
cuFlag?: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@ObjectType()
|
|
54
|
+
export class WorkCodeList {
|
|
55
|
+
@Field(type => [WorkCode])
|
|
56
|
+
items: WorkCode[]
|
|
57
|
+
|
|
58
|
+
@Field(type => Int)
|
|
59
|
+
total: number
|
|
60
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { WorkCodeDetail } from '../work-code-detail/work-code-detail'
|
|
18
|
+
|
|
19
|
+
@Entity()
|
|
20
|
+
@Index('ix_work_code_0', (workCode: WorkCode) => [workCode.domain, workCode.name], { unique: true })
|
|
21
|
+
@Index('ix_work_code_1', (workCode: WorkCode) => [workCode.domain])
|
|
22
|
+
@ObjectType({ description: 'Entity for WorkCode' })
|
|
23
|
+
export class WorkCode {
|
|
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((workCode: WorkCode) => workCode.domain)
|
|
33
|
+
domainId?: string
|
|
34
|
+
|
|
35
|
+
@Column({ type: 'character varying', nullable: false, length: 100 })
|
|
36
|
+
@Field({ nullable: false })
|
|
37
|
+
name: string
|
|
38
|
+
|
|
39
|
+
@Column({ type: 'character varying', nullable: true, length: 200 })
|
|
40
|
+
@Field({ nullable: true })
|
|
41
|
+
description?: string
|
|
42
|
+
|
|
43
|
+
@Column({ type: 'character varying', nullable: true, length: 100 })
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
category1?: string
|
|
46
|
+
|
|
47
|
+
@Column({ type: 'character varying', nullable: true, length: 100 })
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
category2?: string
|
|
50
|
+
|
|
51
|
+
@Column({ type: 'character varying', nullable: true, length: 100 })
|
|
52
|
+
@Field({ nullable: true })
|
|
53
|
+
category3?: string
|
|
54
|
+
|
|
55
|
+
@OneToMany(type => WorkCodeDetail, workCodeDetail => workCodeDetail.workCode)
|
|
56
|
+
details: WorkCodeDetail[]
|
|
57
|
+
|
|
58
|
+
@CreateDateColumn()
|
|
59
|
+
@Field({ nullable: true })
|
|
60
|
+
createdAt?: Date
|
|
61
|
+
|
|
62
|
+
@UpdateDateColumn()
|
|
63
|
+
@Field({ nullable: true })
|
|
64
|
+
updatedAt?: Date
|
|
65
|
+
|
|
66
|
+
@ManyToOne(type => User, {
|
|
67
|
+
nullable: true
|
|
68
|
+
})
|
|
69
|
+
@Field(type => User, { nullable: true })
|
|
70
|
+
creator?: User
|
|
71
|
+
|
|
72
|
+
@RelationId((workCode: WorkCode) => workCode.creator)
|
|
73
|
+
creatorId?: string
|
|
74
|
+
|
|
75
|
+
@ManyToOne(type => User, {
|
|
76
|
+
nullable: true
|
|
77
|
+
})
|
|
78
|
+
@Field(type => User, { nullable: true })
|
|
79
|
+
updater?: User
|
|
80
|
+
|
|
81
|
+
@RelationId((workCode: WorkCode) => workCode.updater)
|
|
82
|
+
updaterId?: string
|
|
83
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WorkCodeDetail } from './work-code-detail'
|
|
2
|
+
import { WorkCodeDetailQuery } from './work-code-detail-query'
|
|
3
|
+
import { WorkCodeDetailMutation } from './work-code-detail-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [WorkCodeDetail]
|
|
6
|
+
export const resolvers = [WorkCodeDetailQuery, WorkCodeDetailMutation]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { WorkCode } from '../work-code/work-code'
|
|
5
|
+
import { WorkCodeDetail } from './work-code-detail'
|
|
6
|
+
import { WorkCodeDetailPatch, NewWorkCodeDetail } from './work-code-detail-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(WorkCodeDetail)
|
|
9
|
+
export class WorkCodeDetailMutation {
|
|
10
|
+
@Directive('@transaction')
|
|
11
|
+
@Mutation(returns => WorkCodeDetail, { description: 'To create new WorkCodeDetail' })
|
|
12
|
+
async createWorkCodeDetail(
|
|
13
|
+
@Arg('commonCodeDetail') workCodeDetail: NewWorkCodeDetail,
|
|
14
|
+
@Ctx() context: ResolverContext
|
|
15
|
+
): Promise<WorkCodeDetail> {
|
|
16
|
+
const { domain, user, tx } = context.state
|
|
17
|
+
|
|
18
|
+
if (workCodeDetail && workCodeDetail.workCode.id) {
|
|
19
|
+
workCodeDetail.workCode = await tx.getRepository(WorkCode).findOneBy({ id: workCodeDetail.workCode.id })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return await tx.getRepository(WorkCodeDetail).save({
|
|
23
|
+
...workCodeDetail,
|
|
24
|
+
domain,
|
|
25
|
+
creator: user,
|
|
26
|
+
updater: user
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Directive('@transaction')
|
|
31
|
+
@Mutation(returns => WorkCodeDetail, { description: 'To modify WorkCodeDetail information' })
|
|
32
|
+
async updateWorkCodeDetail(
|
|
33
|
+
@Arg('id') id: string,
|
|
34
|
+
@Arg('patch') patch: WorkCodeDetailPatch,
|
|
35
|
+
@Ctx() context: ResolverContext
|
|
36
|
+
): Promise<WorkCodeDetail> {
|
|
37
|
+
const { domain, user, tx } = context.state
|
|
38
|
+
|
|
39
|
+
const repository = tx.getRepository(WorkCodeDetail)
|
|
40
|
+
const commonCodeDetail = await repository.findOne({
|
|
41
|
+
where: { id }
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (patch.workCode && patch.workCode.id) {
|
|
45
|
+
patch.workCode = await tx.getRepository(WorkCode).findOneBy({ id: patch.workCode.id })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return await repository.save({
|
|
49
|
+
...commonCodeDetail,
|
|
50
|
+
...patch,
|
|
51
|
+
updater: user
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Directive('@transaction')
|
|
56
|
+
@Mutation(returns => [WorkCodeDetail], { description: "To modify multiple WorkCodeDetails' information" })
|
|
57
|
+
async updateMultipleWorkCodeDetail(
|
|
58
|
+
@Arg('patches', type => [WorkCodeDetailPatch]) patches: WorkCodeDetailPatch[],
|
|
59
|
+
@Ctx() context: ResolverContext
|
|
60
|
+
): Promise<WorkCodeDetail[]> {
|
|
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 workCodeRepo = tx.getRepository(WorkCode)
|
|
67
|
+
const workCodeDetailRepo = tx.getRepository(WorkCodeDetail)
|
|
68
|
+
|
|
69
|
+
if (_createRecords.length > 0) {
|
|
70
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
71
|
+
const newRecord = _createRecords[i]
|
|
72
|
+
|
|
73
|
+
if (newRecord.workCode && newRecord.workCode.id) {
|
|
74
|
+
newRecord.workCode = await workCodeRepo.findOneBy({ id: newRecord.workCode.id })
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const result = await workCodeDetailRepo.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 workCodeDetailRepo.findOneBy({ id: newRecord.id })
|
|
92
|
+
|
|
93
|
+
if (newRecord.workCode && newRecord.workCode.id) {
|
|
94
|
+
newRecord.workCode = await workCodeRepo.findOneBy({ id: newRecord.workCode.id })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const result = await workCodeDetailRepo.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 WorkCodeDetail' })
|
|
112
|
+
async deleteWorkCodeDetail(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
113
|
+
const { domain, tx } = context.state
|
|
114
|
+
|
|
115
|
+
await tx.getRepository(WorkCodeDetail).delete({ id })
|
|
116
|
+
return true
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@Directive('@transaction')
|
|
120
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple WorkCodeDetails' })
|
|
121
|
+
async deleteWorkCodeDetails(
|
|
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(WorkCodeDetail).delete({id: In(ids)})
|
|
128
|
+
return true
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Directive('@transaction')
|
|
132
|
+
@Mutation(returns => Boolean, { description: 'To import multiple WorkCodeDetails' })
|
|
133
|
+
async importWorkCodeDetails(
|
|
134
|
+
@Arg('commonCodeDetails', type => [WorkCodeDetailPatch]) commonCodeDetails: WorkCodeDetailPatch[],
|
|
135
|
+
@Ctx() context: ResolverContext
|
|
136
|
+
): Promise<boolean> {
|
|
137
|
+
const { domain, tx } = context.state
|
|
138
|
+
|
|
139
|
+
await Promise.all(
|
|
140
|
+
commonCodeDetails.map(async (workCodeDetail: WorkCodeDetailPatch) => {
|
|
141
|
+
const createdWorkCodeDetail: WorkCodeDetail = await tx
|
|
142
|
+
.getRepository(WorkCodeDetail)
|
|
143
|
+
.save({ domain, ...workCodeDetail })
|
|
144
|
+
})
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
return true
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Arg, Args, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { WorkCode } from '../work-code/work-code'
|
|
7
|
+
import { WorkCodeDetail } from './work-code-detail'
|
|
8
|
+
import { WorkCodeDetailList } from './work-code-detail-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(WorkCodeDetail)
|
|
11
|
+
export class WorkCodeDetailQuery {
|
|
12
|
+
@Query(returns => WorkCodeDetail, { description: 'To fetch a CommonCodeDetail' })
|
|
13
|
+
async workCodeDetail(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<WorkCodeDetail> {
|
|
14
|
+
const { domain } = context.state
|
|
15
|
+
|
|
16
|
+
return await getRepository(WorkCodeDetail).findOne({
|
|
17
|
+
where: { id }
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Query(returns => WorkCodeDetailList, { description: 'To fetch multiple CommonCodeDetails' })
|
|
22
|
+
async workCodeDetails(
|
|
23
|
+
@Args(type => ListParam) params: ListParam,
|
|
24
|
+
@Ctx() context: ResolverContext
|
|
25
|
+
): Promise<WorkCodeDetailList> {
|
|
26
|
+
const { domain } = context.state
|
|
27
|
+
|
|
28
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
29
|
+
domain,
|
|
30
|
+
params,
|
|
31
|
+
repository: await getRepository(WorkCodeDetail),
|
|
32
|
+
searchables: ['name', 'description']
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
36
|
+
|
|
37
|
+
return { items, total }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@FieldResolver(type => WorkCode)
|
|
41
|
+
async workCode(workCodeDetail): Promise<WorkCode> {
|
|
42
|
+
return await getRepository(WorkCode).findOneBy({ id: workCodeDetail.workCodeId })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@FieldResolver(type => Domain)
|
|
46
|
+
async domain(@Root() workCodeDetail: WorkCodeDetail): Promise<Domain> {
|
|
47
|
+
return await getRepository(Domain).findOneBy({ id: workCodeDetail.domainId })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@FieldResolver(type => User)
|
|
51
|
+
async updater(@Root() workCodeDetail: WorkCodeDetail): Promise<User> {
|
|
52
|
+
return await getRepository(User).findOneBy({ id: workCodeDetail.updaterId })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@FieldResolver(type => User)
|
|
56
|
+
async creator(@Root() workCodeDetail: WorkCodeDetail): Promise<User> {
|
|
57
|
+
return await getRepository(User).findOneBy({ id: workCodeDetail.creatorId })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -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 { WorkCodeDetail } from './work-code-detail'
|
|
6
|
+
|
|
7
|
+
@InputType()
|
|
8
|
+
export class NewWorkCodeDetail {
|
|
9
|
+
@Field()
|
|
10
|
+
name: string
|
|
11
|
+
|
|
12
|
+
@Field({ nullable: true })
|
|
13
|
+
description?: string
|
|
14
|
+
|
|
15
|
+
@Field(type => ObjectRef!)
|
|
16
|
+
workCode: ObjectRef
|
|
17
|
+
|
|
18
|
+
@Field()
|
|
19
|
+
rank: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@InputType()
|
|
23
|
+
export class WorkCodeDetailPatch {
|
|
24
|
+
@Field(type => ID, { nullable: true })
|
|
25
|
+
id?: string
|
|
26
|
+
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
name?: string
|
|
29
|
+
|
|
30
|
+
@Field({ nullable: true })
|
|
31
|
+
description?: string
|
|
32
|
+
|
|
33
|
+
@Field(type => ObjectRef!)
|
|
34
|
+
workCode: ObjectRef
|
|
35
|
+
|
|
36
|
+
@Field({ nullable: true })
|
|
37
|
+
rank?: number
|
|
38
|
+
|
|
39
|
+
@Field({ nullable: true })
|
|
40
|
+
cuFlag?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ObjectType()
|
|
44
|
+
export class WorkCodeDetailList {
|
|
45
|
+
@Field(type => [WorkCodeDetail])
|
|
46
|
+
items: WorkCodeDetail[]
|
|
47
|
+
|
|
48
|
+
@Field(type => Int)
|
|
49
|
+
total: number
|
|
50
|
+
}
|