@things-factory/organization 6.0.0-zeta.26
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/CHANGELOG.md +8 -0
- package/assets/images/hatiolab-logo.png +0 -0
- package/client/bootstrap.ts +1 -0
- package/client/index.ts +0 -0
- package/client/pages/department/department-importer.ts +97 -0
- package/client/pages/department/department-list-page.ts +348 -0
- package/client/pages/employee/employee-importer.ts +97 -0
- package/client/pages/employee/employee-list-page.ts +348 -0
- package/client/pages/main.ts +25 -0
- package/client/route.ts +11 -0
- package/client/tsconfig.json +11 -0
- package/dist-client/actions/main.d.ts +1 -0
- package/dist-client/actions/main.js +2 -0
- package/dist-client/actions/main.js.map +1 -0
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +2 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/index.d.ts +0 -0
- package/dist-client/index.js +2 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/pages/department/department-importer.d.ts +22 -0
- package/dist-client/pages/department/department-importer.js +100 -0
- package/dist-client/pages/department/department-importer.js.map +1 -0
- package/dist-client/pages/department/department-list-page.d.ts +62 -0
- package/dist-client/pages/department/department-list-page.js +326 -0
- package/dist-client/pages/department/department-list-page.js.map +1 -0
- package/dist-client/pages/employee/employee-importer.d.ts +22 -0
- package/dist-client/pages/employee/employee-importer.js +100 -0
- package/dist-client/pages/employee/employee-importer.js.map +1 -0
- package/dist-client/pages/employee/employee-list-page.d.ts +62 -0
- package/dist-client/pages/employee/employee-list-page.js +326 -0
- package/dist-client/pages/employee/employee-list-page.js.map +1 -0
- package/dist-client/pages/main.d.ts +1 -0
- package/dist-client/pages/main.js +27 -0
- package/dist-client/pages/main.js.map +1 -0
- package/dist-client/reducers/main.d.ts +6 -0
- package/dist-client/reducers/main.js +14 -0
- package/dist-client/reducers/main.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +11 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/controllers/index.js +1 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/index.js +7 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/middlewares/index.js +8 -0
- package/dist-server/middlewares/index.js.map +1 -0
- package/dist-server/migrations/index.js +12 -0
- package/dist-server/migrations/index.js.map +1 -0
- package/dist-server/routes.js +25 -0
- package/dist-server/routes.js.map +1 -0
- package/dist-server/service/department/department-history.js +156 -0
- package/dist-server/service/department/department-history.js.map +1 -0
- package/dist-server/service/department/department-mutation.js +168 -0
- package/dist-server/service/department/department-mutation.js.map +1 -0
- package/dist-server/service/department/department-query.js +97 -0
- package/dist-server/service/department/department-query.js.map +1 -0
- package/dist-server/service/department/department-type.js +90 -0
- package/dist-server/service/department/department-type.js.map +1 -0
- package/dist-server/service/department/department.js +145 -0
- package/dist-server/service/department/department.js.map +1 -0
- package/dist-server/service/department/event-subscriber.js +21 -0
- package/dist-server/service/department/event-subscriber.js.map +1 -0
- package/dist-server/service/department/index.js +12 -0
- package/dist-server/service/department/index.js.map +1 -0
- package/dist-server/service/employee/employee-history.js +157 -0
- package/dist-server/service/employee/employee-history.js.map +1 -0
- package/dist-server/service/employee/employee-mutation.js +168 -0
- package/dist-server/service/employee/employee-mutation.js.map +1 -0
- package/dist-server/service/employee/employee-query.js +97 -0
- package/dist-server/service/employee/employee-query.js.map +1 -0
- package/dist-server/service/employee/employee-type.js +90 -0
- package/dist-server/service/employee/employee-type.js.map +1 -0
- package/dist-server/service/employee/employee.js +148 -0
- package/dist-server/service/employee/employee.js.map +1 -0
- package/dist-server/service/employee/event-subscriber.js +21 -0
- package/dist-server/service/employee/event-subscriber.js.map +1 -0
- package/dist-server/service/employee/index.js +12 -0
- package/dist-server/service/employee/index.js.map +1 -0
- package/dist-server/service/index.js +28 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/helps/organization/department.md +160 -0
- package/helps/organization/employee.md +160 -0
- package/package.json +35 -0
- package/server/controllers/index.ts +0 -0
- package/server/index.ts +4 -0
- package/server/middlewares/index.ts +3 -0
- package/server/migrations/index.ts +9 -0
- package/server/routes.ts +28 -0
- package/server/service/department/department-history.ts +137 -0
- package/server/service/department/department-mutation.ts +201 -0
- package/server/service/department/department-query.ts +62 -0
- package/server/service/department/department-type.ts +64 -0
- package/server/service/department/department.ts +124 -0
- package/server/service/department/event-subscriber.ts +17 -0
- package/server/service/department/index.ts +9 -0
- package/server/service/employee/employee-history.ts +137 -0
- package/server/service/employee/employee-mutation.ts +198 -0
- package/server/service/employee/employee-query.ts +62 -0
- package/server/service/employee/employee-type.ts +64 -0
- package/server/service/employee/employee.ts +126 -0
- package/server/service/employee/event-subscriber.ts +17 -0
- package/server/service/employee/index.ts +9 -0
- package/server/service/index.ts +27 -0
- package/server/tsconfig.json +10 -0
- package/things-factory.config.js +11 -0
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
|
|
5
|
+
|
|
6
|
+
import { Department } from './department'
|
|
7
|
+
import { NewDepartment, DepartmentPatch } from './department-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(Department)
|
|
10
|
+
export class DepartmentMutation {
|
|
11
|
+
@Directive('@transaction')
|
|
12
|
+
@Mutation(returns => Department, { description: 'To create new Department' })
|
|
13
|
+
async createDepartment(
|
|
14
|
+
@Arg('department') department: NewDepartment,
|
|
15
|
+
@Ctx() context: ResolverContext
|
|
16
|
+
): Promise<Department> {
|
|
17
|
+
const { domain, user, tx } = context.state
|
|
18
|
+
|
|
19
|
+
const result = await tx.getRepository(Department).save({
|
|
20
|
+
...department,
|
|
21
|
+
domain,
|
|
22
|
+
creator: user,
|
|
23
|
+
updater: user
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if (department.picture) {
|
|
27
|
+
await createAttachment(
|
|
28
|
+
null,
|
|
29
|
+
{
|
|
30
|
+
attachment: {
|
|
31
|
+
file: department.picture,
|
|
32
|
+
refType: Department.name,
|
|
33
|
+
refBy: result.id
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
context
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Directive('@transaction')
|
|
44
|
+
@Mutation(returns => Department, { description: 'To modify Department information' })
|
|
45
|
+
async updateDepartment(
|
|
46
|
+
@Arg('id') id: string,
|
|
47
|
+
@Arg('patch') patch: DepartmentPatch,
|
|
48
|
+
@Ctx() context: ResolverContext
|
|
49
|
+
): Promise<Department> {
|
|
50
|
+
const { domain, user, tx } = context.state
|
|
51
|
+
|
|
52
|
+
const repository = tx.getRepository(Department)
|
|
53
|
+
const department = await repository.findOne({
|
|
54
|
+
where: { domain: { id: domain.id }, id }
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const result = await repository.save({
|
|
58
|
+
...department,
|
|
59
|
+
...patch,
|
|
60
|
+
updater: user
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if (patch.picture) {
|
|
64
|
+
await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
|
|
65
|
+
await createAttachment(
|
|
66
|
+
null,
|
|
67
|
+
{
|
|
68
|
+
attachment: {
|
|
69
|
+
file: patch.picture,
|
|
70
|
+
refType: Department.name,
|
|
71
|
+
refBy: result.id
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
context
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Directive('@transaction')
|
|
82
|
+
@Mutation(returns => [Department], { description: "To modify multiple Departments' information" })
|
|
83
|
+
async updateMultipleDepartment(
|
|
84
|
+
@Arg('patches', type => [DepartmentPatch]) patches: DepartmentPatch[],
|
|
85
|
+
@Ctx() context: ResolverContext
|
|
86
|
+
): Promise<Department[]> {
|
|
87
|
+
const { domain, user, tx } = context.state
|
|
88
|
+
|
|
89
|
+
let results = []
|
|
90
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
91
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
92
|
+
const departmentRepo = tx.getRepository(Department)
|
|
93
|
+
|
|
94
|
+
if (_createRecords.length > 0) {
|
|
95
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
96
|
+
const newRecord = _createRecords[i]
|
|
97
|
+
|
|
98
|
+
const result = await departmentRepo.save({
|
|
99
|
+
...newRecord,
|
|
100
|
+
domain,
|
|
101
|
+
creator: user,
|
|
102
|
+
updater: user
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
if (newRecord.picture) {
|
|
106
|
+
await createAttachment(
|
|
107
|
+
null,
|
|
108
|
+
{
|
|
109
|
+
attachment: {
|
|
110
|
+
file: newRecord.picture,
|
|
111
|
+
refType: Department.name,
|
|
112
|
+
refBy: result.id
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
context
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
results.push({ ...result, cuFlag: '+' })
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (_updateRecords.length > 0) {
|
|
124
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
125
|
+
const updateRecord = _updateRecords[i]
|
|
126
|
+
const department = await departmentRepo.findOneBy({ id: updateRecord.id })
|
|
127
|
+
|
|
128
|
+
const result = await departmentRepo.save({
|
|
129
|
+
...department,
|
|
130
|
+
...updateRecord,
|
|
131
|
+
updater: user
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
if (updateRecord.picture) {
|
|
135
|
+
await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
|
|
136
|
+
await createAttachment(
|
|
137
|
+
null,
|
|
138
|
+
{
|
|
139
|
+
attachment: {
|
|
140
|
+
file: updateRecord.picture,
|
|
141
|
+
refType: Department.name,
|
|
142
|
+
refBy: result.id
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
context
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return results
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@Directive('@transaction')
|
|
157
|
+
@Mutation(returns => Boolean, { description: 'To delete Department' })
|
|
158
|
+
async deleteDepartment(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
159
|
+
const { domain, tx } = context.state
|
|
160
|
+
|
|
161
|
+
await tx.getRepository(Department).delete({ domain: { id: domain.id }, id })
|
|
162
|
+
await deleteAttachmentsByRef(null, { refBys: [id] }, context)
|
|
163
|
+
|
|
164
|
+
return true
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@Directive('@transaction')
|
|
168
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple Departments' })
|
|
169
|
+
async deleteDepartments(
|
|
170
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
171
|
+
@Ctx() context: ResolverContext
|
|
172
|
+
): Promise<boolean> {
|
|
173
|
+
const { domain, tx } = context.state
|
|
174
|
+
|
|
175
|
+
await tx.getRepository(Department).delete({
|
|
176
|
+
domain: { id: domain.id },
|
|
177
|
+
id: In(ids)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
await deleteAttachmentsByRef(null, { refBys: ids }, context)
|
|
181
|
+
|
|
182
|
+
return true
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@Directive('@transaction')
|
|
186
|
+
@Mutation(returns => Boolean, { description: 'To import multiple Departments' })
|
|
187
|
+
async importDepartments(
|
|
188
|
+
@Arg('departments', type => [DepartmentPatch]) departments: DepartmentPatch[],
|
|
189
|
+
@Ctx() context: ResolverContext
|
|
190
|
+
): Promise<boolean> {
|
|
191
|
+
const { domain, tx } = context.state
|
|
192
|
+
|
|
193
|
+
await Promise.all(
|
|
194
|
+
departments.map(async (department: DepartmentPatch) => {
|
|
195
|
+
const createdDepartment: Department = await tx.getRepository(Department).save({ domain, ...department })
|
|
196
|
+
})
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return true
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { Attachment } from '@things-factory/attachment-base'
|
|
3
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
4
|
+
import { User } from '@things-factory/auth-base'
|
|
5
|
+
import { Department } from './department'
|
|
6
|
+
import { DepartmentList } from './department-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(Department)
|
|
9
|
+
export class DepartmentQuery {
|
|
10
|
+
@Query(returns => Department!, { nullable: true, description: 'To fetch a Department' })
|
|
11
|
+
async department(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Department> {
|
|
12
|
+
const { domain } = context.state
|
|
13
|
+
|
|
14
|
+
return await getRepository(Department).findOne({
|
|
15
|
+
where: { domain: { id: domain.id }, id }
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Query(returns => DepartmentList, { description: 'To fetch multiple Departments' })
|
|
20
|
+
async departments(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<DepartmentList> {
|
|
21
|
+
const { domain } = context.state
|
|
22
|
+
|
|
23
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
24
|
+
domain,
|
|
25
|
+
params,
|
|
26
|
+
repository: await getRepository(Department),
|
|
27
|
+
searchables: ['name', 'description']
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
31
|
+
|
|
32
|
+
return { items, total }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@FieldResolver(type => String)
|
|
36
|
+
async picture(@Root() department: Department): Promise<string | undefined> {
|
|
37
|
+
const attachment: Attachment = await getRepository(Attachment).findOne({
|
|
38
|
+
where: {
|
|
39
|
+
domain: { id: department.domainId },
|
|
40
|
+
refType: Department.name,
|
|
41
|
+
refBy: department.id
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return attachment?.fullpath
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@FieldResolver(type => Domain)
|
|
49
|
+
async domain(@Root() department: Department): Promise<Domain> {
|
|
50
|
+
return await getRepository(Domain).findOneBy({ id: department.domainId })
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@FieldResolver(type => User)
|
|
54
|
+
async updater(@Root() department: Department): Promise<User> {
|
|
55
|
+
return await getRepository(User).findOneBy({ id: department.updaterId })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@FieldResolver(type => User)
|
|
59
|
+
async creator(@Root() department: Department): Promise<User> {
|
|
60
|
+
return await getRepository(User).findOneBy({ id: department.creatorId })
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
|
|
2
|
+
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
|
|
3
|
+
import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
|
|
4
|
+
|
|
5
|
+
import { ObjectRef, ScalarObject } from '@things-factory/shell'
|
|
6
|
+
|
|
7
|
+
import { Department, DepartmentStatus } from './department'
|
|
8
|
+
|
|
9
|
+
@InputType()
|
|
10
|
+
export class NewDepartment {
|
|
11
|
+
@Field()
|
|
12
|
+
controlNo: string
|
|
13
|
+
|
|
14
|
+
@Field()
|
|
15
|
+
name: string
|
|
16
|
+
|
|
17
|
+
@Field({ nullable: true })
|
|
18
|
+
description?: string
|
|
19
|
+
|
|
20
|
+
@Field(type => DepartmentStatus, { nullable: true })
|
|
21
|
+
state?: DepartmentStatus
|
|
22
|
+
|
|
23
|
+
@Field({ nullable: true })
|
|
24
|
+
active?: boolean
|
|
25
|
+
|
|
26
|
+
@Field({ nullable: true })
|
|
27
|
+
extension?: string
|
|
28
|
+
|
|
29
|
+
@Field(type => GraphQLUpload, { nullable: true })
|
|
30
|
+
picture?: FileUpload
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@InputType()
|
|
34
|
+
export class DepartmentPatch {
|
|
35
|
+
@Field(type => ID, { nullable: true })
|
|
36
|
+
id?: string
|
|
37
|
+
|
|
38
|
+
@Field({ nullable: true })
|
|
39
|
+
name?: string
|
|
40
|
+
|
|
41
|
+
@Field({ nullable: true })
|
|
42
|
+
description?: string
|
|
43
|
+
|
|
44
|
+
@Field(type => DepartmentStatus, { nullable: true })
|
|
45
|
+
state?: DepartmentStatus
|
|
46
|
+
|
|
47
|
+
@Field({ nullable: true })
|
|
48
|
+
active?: boolean
|
|
49
|
+
|
|
50
|
+
@Field(type => GraphQLUpload, { nullable: true })
|
|
51
|
+
picture?: FileUpload
|
|
52
|
+
|
|
53
|
+
@Field({ nullable: true })
|
|
54
|
+
cuFlag?: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ObjectType()
|
|
58
|
+
export class DepartmentList {
|
|
59
|
+
@Field(type => [Department])
|
|
60
|
+
items: Department[]
|
|
61
|
+
|
|
62
|
+
@Field(type => Int)
|
|
63
|
+
total: number
|
|
64
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateDateColumn,
|
|
3
|
+
UpdateDateColumn,
|
|
4
|
+
DeleteDateColumn,
|
|
5
|
+
Entity,
|
|
6
|
+
Index,
|
|
7
|
+
Column,
|
|
8
|
+
RelationId,
|
|
9
|
+
ManyToOne,
|
|
10
|
+
OneToMany,
|
|
11
|
+
PrimaryGeneratedColumn,
|
|
12
|
+
VersionColumn
|
|
13
|
+
} from 'typeorm'
|
|
14
|
+
import { ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
|
|
15
|
+
|
|
16
|
+
import { Domain } from '@things-factory/shell'
|
|
17
|
+
import { User } from '@things-factory/auth-base'
|
|
18
|
+
import { Employee } from '../employee/employee'
|
|
19
|
+
|
|
20
|
+
export enum DepartmentStatus {
|
|
21
|
+
STATUS_A = 'STATUS_A',
|
|
22
|
+
STATUS_B = 'STATUS_B'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
registerEnumType(DepartmentStatus, {
|
|
26
|
+
name: 'DepartmentStatus',
|
|
27
|
+
description: 'state enumeration of a department'
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
@Entity()
|
|
31
|
+
@Index('ix_department_0', (department: Department) => [department.domain, department.name, department.deletedAt], {
|
|
32
|
+
unique: true
|
|
33
|
+
})
|
|
34
|
+
@Index('ix_department_1', (department: Department) => [department.domain, department.controlNo, department.deletedAt], {
|
|
35
|
+
unique: true
|
|
36
|
+
})
|
|
37
|
+
@ObjectType({ description: 'Entity for Department' })
|
|
38
|
+
export class Department {
|
|
39
|
+
@PrimaryGeneratedColumn('uuid')
|
|
40
|
+
@Field(type => ID)
|
|
41
|
+
readonly id: string
|
|
42
|
+
|
|
43
|
+
@VersionColumn()
|
|
44
|
+
@Field({ nullable: true })
|
|
45
|
+
version?: number = 1
|
|
46
|
+
|
|
47
|
+
@ManyToOne(type => Domain)
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
domain?: Domain
|
|
50
|
+
|
|
51
|
+
@RelationId((department: Department) => department.domain)
|
|
52
|
+
domainId?: string
|
|
53
|
+
|
|
54
|
+
@Column()
|
|
55
|
+
@Field()
|
|
56
|
+
controlNo: string
|
|
57
|
+
|
|
58
|
+
@Column()
|
|
59
|
+
@Field()
|
|
60
|
+
name: string
|
|
61
|
+
|
|
62
|
+
@Column({ nullable: true })
|
|
63
|
+
@Field({ nullable: true })
|
|
64
|
+
description?: string
|
|
65
|
+
|
|
66
|
+
@ManyToOne(type => Department, department => department.children, { nullable: true })
|
|
67
|
+
@Field({ nullable: true })
|
|
68
|
+
parent?: Department
|
|
69
|
+
|
|
70
|
+
@RelationId((department: Department) => department.parent)
|
|
71
|
+
parentId?: string
|
|
72
|
+
|
|
73
|
+
@OneToMany(type => Department, department => department.parent)
|
|
74
|
+
@Field(type => [Department])
|
|
75
|
+
children?: Department[]
|
|
76
|
+
|
|
77
|
+
@ManyToOne(type => Employee, manager => manager.manages, { nullable: true })
|
|
78
|
+
@Field({ nullable: true })
|
|
79
|
+
manager?: Employee
|
|
80
|
+
|
|
81
|
+
@RelationId((department: Department) => department.manager)
|
|
82
|
+
managerId?: string
|
|
83
|
+
|
|
84
|
+
@Column({ nullable: true })
|
|
85
|
+
@Field({ nullable: true })
|
|
86
|
+
active?: boolean
|
|
87
|
+
|
|
88
|
+
@Column({ nullable: true })
|
|
89
|
+
@Field({ nullable: true })
|
|
90
|
+
state?: DepartmentStatus
|
|
91
|
+
|
|
92
|
+
@Column({ nullable: true })
|
|
93
|
+
@Field({ nullable: true })
|
|
94
|
+
extension?: string
|
|
95
|
+
|
|
96
|
+
@Field(type => String, { nullable: true })
|
|
97
|
+
picture?: string
|
|
98
|
+
|
|
99
|
+
@CreateDateColumn()
|
|
100
|
+
@Field({ nullable: true })
|
|
101
|
+
createdAt?: Date
|
|
102
|
+
|
|
103
|
+
@UpdateDateColumn()
|
|
104
|
+
@Field({ nullable: true })
|
|
105
|
+
updatedAt?: Date
|
|
106
|
+
|
|
107
|
+
@DeleteDateColumn()
|
|
108
|
+
@Field({ nullable: true })
|
|
109
|
+
deletedAt?: Date
|
|
110
|
+
|
|
111
|
+
@ManyToOne(type => User, { nullable: true })
|
|
112
|
+
@Field({ nullable: true })
|
|
113
|
+
creator?: User
|
|
114
|
+
|
|
115
|
+
@RelationId((department: Department) => department.creator)
|
|
116
|
+
creatorId?: string
|
|
117
|
+
|
|
118
|
+
@ManyToOne(type => User, { nullable: true })
|
|
119
|
+
@Field({ nullable: true })
|
|
120
|
+
updater?: User
|
|
121
|
+
|
|
122
|
+
@RelationId((department: Department) => department.updater)
|
|
123
|
+
updaterId?: string
|
|
124
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventSubscriber } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { HistoryEntitySubscriber } from '@anchan828/typeorm-history'
|
|
4
|
+
|
|
5
|
+
import { Department } from './department'
|
|
6
|
+
import { DepartmentHistory } from './department-history'
|
|
7
|
+
|
|
8
|
+
@EventSubscriber()
|
|
9
|
+
export class DepartmentHistoryEntitySubscriber extends HistoryEntitySubscriber<Department, DepartmentHistory> {
|
|
10
|
+
public get entity() {
|
|
11
|
+
return Department
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get historyEntity() {
|
|
15
|
+
return DepartmentHistory
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Department } from './department'
|
|
2
|
+
import { DepartmentHistory } from './department-history'
|
|
3
|
+
import { DepartmentQuery } from './department-query'
|
|
4
|
+
import { DepartmentMutation } from './department-mutation'
|
|
5
|
+
import { DepartmentHistoryEntitySubscriber } from './event-subscriber'
|
|
6
|
+
|
|
7
|
+
export const entities = [Department, DepartmentHistory]
|
|
8
|
+
export const resolvers = [DepartmentQuery, DepartmentMutation]
|
|
9
|
+
export const subscribers = [DepartmentHistoryEntitySubscriber]
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import { Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, RelationId } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
HistoryActionColumn,
|
|
6
|
+
HistoryActionType,
|
|
7
|
+
HistoryEntityInterface,
|
|
8
|
+
HistoryOriginalIdColumn
|
|
9
|
+
} from '@anchan828/typeorm-history'
|
|
10
|
+
import { Role, User } from '@things-factory/auth-base'
|
|
11
|
+
import { config } from '@things-factory/env'
|
|
12
|
+
import { Domain } from '@things-factory/shell'
|
|
13
|
+
|
|
14
|
+
import { Employee, EmployeeStatus } from './employee'
|
|
15
|
+
import { Department } from '../department/department'
|
|
16
|
+
|
|
17
|
+
const ORMCONFIG = config.get('ormconfig', {})
|
|
18
|
+
const DATABASE_TYPE = ORMCONFIG.type
|
|
19
|
+
|
|
20
|
+
@Entity()
|
|
21
|
+
@Index(
|
|
22
|
+
'ix_employee_history_0',
|
|
23
|
+
(employeeHistory: EmployeeHistory) => [employeeHistory.originalId, employeeHistory.version],
|
|
24
|
+
{ unique: true }
|
|
25
|
+
)
|
|
26
|
+
@Index(
|
|
27
|
+
'ix_employee_history_1',
|
|
28
|
+
(employeeHistory: EmployeeHistory) => [employeeHistory.domain, employeeHistory.originalId, employeeHistory.version],
|
|
29
|
+
{ unique: true }
|
|
30
|
+
)
|
|
31
|
+
@ObjectType({ description: 'History Entity of Employee' })
|
|
32
|
+
export class EmployeeHistory implements HistoryEntityInterface<Employee> {
|
|
33
|
+
@PrimaryGeneratedColumn('uuid')
|
|
34
|
+
@Field(type => ID)
|
|
35
|
+
readonly id: string
|
|
36
|
+
|
|
37
|
+
@Column({ nullable: true, default: 1 })
|
|
38
|
+
@Field({ nullable: true })
|
|
39
|
+
version?: number = 1
|
|
40
|
+
|
|
41
|
+
@ManyToOne(type => Domain)
|
|
42
|
+
@Field({ nullable: true })
|
|
43
|
+
domain?: Domain
|
|
44
|
+
|
|
45
|
+
@RelationId((employee: Employee) => employee.domain)
|
|
46
|
+
domainId?: string
|
|
47
|
+
|
|
48
|
+
@Column()
|
|
49
|
+
@Field()
|
|
50
|
+
controlNo: string
|
|
51
|
+
|
|
52
|
+
@Column()
|
|
53
|
+
@Field()
|
|
54
|
+
name: string
|
|
55
|
+
|
|
56
|
+
@Column({ nullable: true })
|
|
57
|
+
@Field({ nullable: true })
|
|
58
|
+
description?: string
|
|
59
|
+
|
|
60
|
+
@ManyToOne(type => Employee, supervisor => supervisor.supervises, { nullable: true })
|
|
61
|
+
@Field({ nullable: true })
|
|
62
|
+
supervisor?: Employee
|
|
63
|
+
|
|
64
|
+
@RelationId((employee: Employee) => employee.supervisor)
|
|
65
|
+
supervisorId?: string
|
|
66
|
+
|
|
67
|
+
@OneToMany(type => Employee, employee => employee.supervisor)
|
|
68
|
+
@Field(type => [Employee])
|
|
69
|
+
supervises?: Employee[]
|
|
70
|
+
|
|
71
|
+
@OneToMany(type => Department, department => department.manager)
|
|
72
|
+
@Field(type => [Department])
|
|
73
|
+
manages?: Department[]
|
|
74
|
+
|
|
75
|
+
@Column({ nullable: true })
|
|
76
|
+
@Field({ nullable: true })
|
|
77
|
+
active?: boolean
|
|
78
|
+
|
|
79
|
+
@Column({ nullable: true })
|
|
80
|
+
@Field({ nullable: true })
|
|
81
|
+
state?: EmployeeStatus
|
|
82
|
+
|
|
83
|
+
@Column({ nullable: true })
|
|
84
|
+
@Field({ nullable: true })
|
|
85
|
+
extension?: string
|
|
86
|
+
|
|
87
|
+
@Column({ nullable: true })
|
|
88
|
+
@Field({ nullable: true })
|
|
89
|
+
createdAt?: Date
|
|
90
|
+
|
|
91
|
+
@Column({ nullable: true })
|
|
92
|
+
@Field({ nullable: true })
|
|
93
|
+
updatedAt?: Date
|
|
94
|
+
|
|
95
|
+
@Column({ nullable: true })
|
|
96
|
+
@Field({ nullable: true })
|
|
97
|
+
deletedAt?: Date
|
|
98
|
+
|
|
99
|
+
@ManyToOne(type => User, { nullable: true })
|
|
100
|
+
@Field({ nullable: true })
|
|
101
|
+
creator?: User
|
|
102
|
+
|
|
103
|
+
@RelationId((employee: Employee) => employee.creator)
|
|
104
|
+
creatorId?: string
|
|
105
|
+
|
|
106
|
+
@ManyToOne(type => User, { nullable: true })
|
|
107
|
+
@Field({ nullable: true })
|
|
108
|
+
updater?: User
|
|
109
|
+
|
|
110
|
+
@RelationId((employee: Employee) => employee.updater)
|
|
111
|
+
updaterId?: string
|
|
112
|
+
|
|
113
|
+
@Field(type => String, { nullable: true })
|
|
114
|
+
photo?: string
|
|
115
|
+
|
|
116
|
+
@ManyToOne(type => User, { nullable: true })
|
|
117
|
+
@Field({ nullable: true })
|
|
118
|
+
user?: User
|
|
119
|
+
|
|
120
|
+
@RelationId((employee: Employee) => employee.user)
|
|
121
|
+
userId?: string
|
|
122
|
+
|
|
123
|
+
@HistoryOriginalIdColumn()
|
|
124
|
+
public originalId!: string
|
|
125
|
+
|
|
126
|
+
@HistoryActionColumn({
|
|
127
|
+
nullable: false,
|
|
128
|
+
type:
|
|
129
|
+
DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
130
|
+
? 'enum'
|
|
131
|
+
: DATABASE_TYPE == 'oracle'
|
|
132
|
+
? 'varchar2'
|
|
133
|
+
: 'smallint',
|
|
134
|
+
enum: HistoryActionType
|
|
135
|
+
})
|
|
136
|
+
public action!: HistoryActionType
|
|
137
|
+
}
|