@things-factory/worklist-client 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 +1 -0
- package/client/index.ts +0 -0
- package/client/pages/work-center/work-center-importer.ts +87 -0
- package/client/pages/work-center/work-center-list-page.ts +323 -0
- package/client/pages/work-center/work-center-page.ts +95 -0
- package/client/route.ts +7 -0
- package/client/tsconfig.json +13 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/server/controllers/activity-registry.ts +17 -0
- package/server/controllers/graphql-client.ts +67 -0
- package/server/controllers/index.ts +4 -0
- package/server/controllers/webhooks/decorators.ts +18 -0
- package/server/controllers/webhooks/index.ts +30 -0
- package/server/controllers/work-center/connect-work-center.ts +15 -0
- package/server/controllers/work-center/get-work-center.ts +9 -0
- package/server/controllers/work-center/index.ts +2 -0
- package/server/controllers/worklist-api/assign-activity-thread.ts +3 -0
- package/server/controllers/worklist-api/draft-activity-instance.ts +3 -0
- package/server/controllers/worklist-api/get-activity-list.ts +3 -0
- package/server/controllers/worklist-api/get-activity.ts +3 -0
- package/server/controllers/worklist-api/get-todo-list.ts +4 -0
- package/server/controllers/worklist-api/index.ts +8 -0
- package/server/controllers/worklist-api/register-activity.ts +3 -0
- package/server/controllers/worklist-api/unregister-activity.ts +3 -0
- package/server/controllers/worklist-api/update-activity.ts +3 -0
- package/server/index.ts +3 -0
- package/server/routes.ts +46 -0
- package/server/service/activity/activity-model-type.ts +106 -0
- package/server/service/activity/activity-mutation.ts +85 -0
- package/server/service/activity/activity-query.ts +64 -0
- package/server/service/activity/activity-type.ts +134 -0
- package/server/service/activity/activity.ts +133 -0
- package/server/service/activity/index.ts +6 -0
- package/server/service/index.ts +36 -0
- package/server/service/work-center/event-subscriber.ts +17 -0
- package/server/service/work-center/index.ts +9 -0
- package/server/service/work-center/work-center-history.ts +120 -0
- package/server/service/work-center/work-center-mutation.ts +198 -0
- package/server/service/work-center/work-center-query.ts +65 -0
- package/server/service/work-center/work-center-type.ts +61 -0
- package/server/service/work-center/work-center.ts +75 -0
- package/server/tsconfig.json +10 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
|
|
2
|
+
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
|
|
3
|
+
import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
|
|
4
|
+
|
|
5
|
+
import { ObjectRef, ScalarObject } from '@things-factory/shell'
|
|
6
|
+
|
|
7
|
+
import { Activity, ActivityType, ActivityUIType } from './activity'
|
|
8
|
+
import { ActivityModelItem } from './activity-model-type'
|
|
9
|
+
|
|
10
|
+
@InputType()
|
|
11
|
+
export class NewActivity {
|
|
12
|
+
@Field()
|
|
13
|
+
name: string
|
|
14
|
+
|
|
15
|
+
@Field({ nullable: true })
|
|
16
|
+
description?: string
|
|
17
|
+
|
|
18
|
+
@Field({ nullable: true })
|
|
19
|
+
activityType?: ActivityType
|
|
20
|
+
|
|
21
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
22
|
+
model?: ActivityModelItem[]
|
|
23
|
+
|
|
24
|
+
@Field({ nullable: true })
|
|
25
|
+
priority?: number
|
|
26
|
+
|
|
27
|
+
@Field({ nullable: true })
|
|
28
|
+
startable?: boolean
|
|
29
|
+
|
|
30
|
+
@Field({ nullable: true })
|
|
31
|
+
schedule?: string
|
|
32
|
+
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
standardTime?: number
|
|
35
|
+
|
|
36
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
37
|
+
issuerRole?: ObjectRef
|
|
38
|
+
|
|
39
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
40
|
+
assigneeRole?: ObjectRef
|
|
41
|
+
|
|
42
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
43
|
+
supervisoryRole?: ObjectRef
|
|
44
|
+
|
|
45
|
+
@Field({ nullable: true })
|
|
46
|
+
uiType?: ActivityUIType
|
|
47
|
+
|
|
48
|
+
@Field({ nullable: true })
|
|
49
|
+
uiSource?: string
|
|
50
|
+
|
|
51
|
+
@Field({ nullable: true })
|
|
52
|
+
viewType?: ActivityUIType
|
|
53
|
+
|
|
54
|
+
@Field({ nullable: true })
|
|
55
|
+
viewSource?: string
|
|
56
|
+
|
|
57
|
+
@Field({ nullable: true })
|
|
58
|
+
reportType?: ActivityUIType
|
|
59
|
+
|
|
60
|
+
@Field({ nullable: true })
|
|
61
|
+
reportSource?: string
|
|
62
|
+
|
|
63
|
+
@Field({ nullable: true })
|
|
64
|
+
active?: boolean
|
|
65
|
+
|
|
66
|
+
@Field(type => GraphQLUpload, { nullable: true })
|
|
67
|
+
thumbnail?: FileUpload
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@InputType()
|
|
71
|
+
export class ActivityPatch {
|
|
72
|
+
@Field(type => ID, { nullable: true })
|
|
73
|
+
id?: string
|
|
74
|
+
|
|
75
|
+
@Field({ nullable: true })
|
|
76
|
+
name?: string
|
|
77
|
+
|
|
78
|
+
@Field({ nullable: true })
|
|
79
|
+
description?: string
|
|
80
|
+
|
|
81
|
+
@Field({ nullable: true })
|
|
82
|
+
activityType?: ActivityType
|
|
83
|
+
|
|
84
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
85
|
+
model?: ActivityModelItem[]
|
|
86
|
+
|
|
87
|
+
@Field({ nullable: true })
|
|
88
|
+
priority?: number
|
|
89
|
+
|
|
90
|
+
@Field({ nullable: true })
|
|
91
|
+
startable?: boolean
|
|
92
|
+
|
|
93
|
+
@Field({ nullable: true })
|
|
94
|
+
schedule?: string
|
|
95
|
+
|
|
96
|
+
@Field({ nullable: true })
|
|
97
|
+
standardTime?: number
|
|
98
|
+
|
|
99
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
100
|
+
issuerRole?: ObjectRef
|
|
101
|
+
|
|
102
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
103
|
+
assigneeRole?: ObjectRef
|
|
104
|
+
|
|
105
|
+
@Field(type => ObjectRef, { nullable: true })
|
|
106
|
+
supervisoryRole?: ObjectRef
|
|
107
|
+
|
|
108
|
+
@Field({ nullable: true })
|
|
109
|
+
uiType?: ActivityUIType
|
|
110
|
+
|
|
111
|
+
@Field({ nullable: true })
|
|
112
|
+
uiSource?: string
|
|
113
|
+
|
|
114
|
+
@Field({ nullable: true })
|
|
115
|
+
reportType?: ActivityUIType
|
|
116
|
+
|
|
117
|
+
@Field({ nullable: true })
|
|
118
|
+
reportSource?: string
|
|
119
|
+
|
|
120
|
+
@Field(type => GraphQLUpload, { nullable: true })
|
|
121
|
+
thumbnail?: FileUpload
|
|
122
|
+
|
|
123
|
+
@Field({ nullable: true })
|
|
124
|
+
cuFlag?: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@ObjectType()
|
|
128
|
+
export class ActivityList {
|
|
129
|
+
@Field(type => [Activity])
|
|
130
|
+
items: Activity[]
|
|
131
|
+
|
|
132
|
+
@Field(type => Int)
|
|
133
|
+
total: number
|
|
134
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Role, User } from '@things-factory/auth-base'
|
|
4
|
+
import { Domain } from '@things-factory/shell'
|
|
5
|
+
|
|
6
|
+
import { ActivityModelItem } from './activity-model-type'
|
|
7
|
+
|
|
8
|
+
export enum ActivityStatus {
|
|
9
|
+
Draft = 'draft',
|
|
10
|
+
Released = 'released',
|
|
11
|
+
Deprecated = 'deprecated'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
registerEnumType(ActivityStatus, {
|
|
15
|
+
name: 'ActivityStatus',
|
|
16
|
+
description: 'state enumeration of a activity'
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export enum ActivityType {
|
|
20
|
+
Task = 'task',
|
|
21
|
+
Service = 'service',
|
|
22
|
+
Send = 'send',
|
|
23
|
+
Receive = 'receive',
|
|
24
|
+
User = 'user',
|
|
25
|
+
Manual = 'manual',
|
|
26
|
+
BusinessRule = 'business-rule',
|
|
27
|
+
Script = 'script',
|
|
28
|
+
Subprocess = 'sub-process',
|
|
29
|
+
Call = 'call'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
registerEnumType(ActivityType, {
|
|
33
|
+
name: 'ActivityType',
|
|
34
|
+
description: 'type enumeration of a activity'
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export enum ActivityUIType {
|
|
38
|
+
Generated = 'generated',
|
|
39
|
+
Template = 'template',
|
|
40
|
+
Board = 'board',
|
|
41
|
+
CustomElement = 'custom-element',
|
|
42
|
+
Page = 'page',
|
|
43
|
+
External = 'external'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
registerEnumType(ActivityUIType, {
|
|
47
|
+
name: 'ActivityUIType',
|
|
48
|
+
description: 'user-interface type enumeration of a activity'
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
@ObjectType({ description: 'Entity for Activity' })
|
|
52
|
+
export class Activity {
|
|
53
|
+
@Field(type => ID)
|
|
54
|
+
readonly id: string
|
|
55
|
+
|
|
56
|
+
@Field({ nullable: true })
|
|
57
|
+
version?: number = 1
|
|
58
|
+
|
|
59
|
+
@Field(type => Domain, { nullable: true })
|
|
60
|
+
domain?: Domain
|
|
61
|
+
|
|
62
|
+
@Field({ nullable: true })
|
|
63
|
+
name?: string
|
|
64
|
+
|
|
65
|
+
@Field({ nullable: true })
|
|
66
|
+
description?: string
|
|
67
|
+
|
|
68
|
+
@Field({ nullable: true })
|
|
69
|
+
activityType?: ActivityType
|
|
70
|
+
|
|
71
|
+
@Field({ nullable: true })
|
|
72
|
+
state?: ActivityStatus
|
|
73
|
+
|
|
74
|
+
@Field(type => [ActivityModelItem], { nullable: true })
|
|
75
|
+
model?: ActivityModelItem[]
|
|
76
|
+
|
|
77
|
+
@Field({ nullable: true })
|
|
78
|
+
priority?: number = 1
|
|
79
|
+
|
|
80
|
+
@Field({ nullable: true })
|
|
81
|
+
startable?: boolean
|
|
82
|
+
|
|
83
|
+
@Field({ nullable: true })
|
|
84
|
+
schedule?: string
|
|
85
|
+
|
|
86
|
+
@Field({ nullable: true })
|
|
87
|
+
standardTime?: number
|
|
88
|
+
|
|
89
|
+
@Field(type => Role, { nullable: true })
|
|
90
|
+
issuerRole?: Role
|
|
91
|
+
|
|
92
|
+
@Field(type => Role, { nullable: true })
|
|
93
|
+
assigneeRole?: Role
|
|
94
|
+
|
|
95
|
+
@Field(type => Role, { nullable: true })
|
|
96
|
+
supervisoryRole?: Role
|
|
97
|
+
|
|
98
|
+
@Field({ nullable: true })
|
|
99
|
+
uiType?: ActivityUIType
|
|
100
|
+
|
|
101
|
+
@Field({ nullable: true })
|
|
102
|
+
uiSource?: string
|
|
103
|
+
|
|
104
|
+
@Field({ nullable: true })
|
|
105
|
+
viewType?: ActivityUIType
|
|
106
|
+
|
|
107
|
+
@Field({ nullable: true })
|
|
108
|
+
viewSource?: string
|
|
109
|
+
|
|
110
|
+
@Field({ nullable: true })
|
|
111
|
+
reportType?: ActivityUIType
|
|
112
|
+
|
|
113
|
+
@Field({ nullable: true })
|
|
114
|
+
reportSource?: string
|
|
115
|
+
|
|
116
|
+
@Field({ nullable: true })
|
|
117
|
+
createdAt?: Date
|
|
118
|
+
|
|
119
|
+
@Field({ nullable: true })
|
|
120
|
+
updatedAt?: Date
|
|
121
|
+
|
|
122
|
+
@Field(type => User, { nullable: true, description: 'User assigned to the client application' })
|
|
123
|
+
client?: User
|
|
124
|
+
|
|
125
|
+
@Field(type => User, { nullable: true })
|
|
126
|
+
creator?: User
|
|
127
|
+
|
|
128
|
+
@Field(type => User, { nullable: true })
|
|
129
|
+
updater?: User
|
|
130
|
+
|
|
131
|
+
@Field(type => String, { nullable: true })
|
|
132
|
+
thumbnail?: string
|
|
133
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/* EXPORT ENTITY TYPES */
|
|
2
|
+
export * from './activity/activity'
|
|
3
|
+
export * from './work-center/work-center'
|
|
4
|
+
|
|
5
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
6
|
+
import {
|
|
7
|
+
entities as ActivityEntities,
|
|
8
|
+
resolvers as ActivityResolvers,
|
|
9
|
+
subscribers as ActivitySubscribers
|
|
10
|
+
} from './activity'
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
entities as WorkCenterEntities,
|
|
14
|
+
resolvers as WorkCenterResolvers,
|
|
15
|
+
subscribers as WorkCenterSubscribers
|
|
16
|
+
} from './work-center'
|
|
17
|
+
|
|
18
|
+
export const entities = [
|
|
19
|
+
/* ENTITIES */
|
|
20
|
+
...ActivityEntities,
|
|
21
|
+
...WorkCenterEntities
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
export const subscribers = [
|
|
25
|
+
/* SUBSCRIBERS */
|
|
26
|
+
...ActivitySubscribers,
|
|
27
|
+
...WorkCenterSubscribers
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
export const schema = {
|
|
31
|
+
resolverClasses: [
|
|
32
|
+
/* RESOLVER CLASSES */
|
|
33
|
+
...ActivityResolvers,
|
|
34
|
+
...WorkCenterResolvers
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EventSubscriber } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { HistoryEntitySubscriber } from '@operato/typeorm-history'
|
|
4
|
+
|
|
5
|
+
import { WorkCenter } from './work-center'
|
|
6
|
+
import { WorkCenterHistory } from './work-center-history'
|
|
7
|
+
|
|
8
|
+
@EventSubscriber()
|
|
9
|
+
export class WorkCenterHistoryEntitySubscriber extends HistoryEntitySubscriber<WorkCenter, WorkCenterHistory> {
|
|
10
|
+
public get entity() {
|
|
11
|
+
return WorkCenter
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get historyEntity() {
|
|
15
|
+
return WorkCenterHistory
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkCenter } from './work-center'
|
|
2
|
+
import { WorkCenterHistory } from './work-center-history'
|
|
3
|
+
import { WorkCenterQuery } from './work-center-query'
|
|
4
|
+
import { WorkCenterMutation } from './work-center-mutation'
|
|
5
|
+
import { WorkCenterHistoryEntitySubscriber } from './event-subscriber'
|
|
6
|
+
|
|
7
|
+
export const entities = [WorkCenter, WorkCenterHistory]
|
|
8
|
+
export const resolvers = [WorkCenterQuery, WorkCenterMutation]
|
|
9
|
+
export const subscribers = [WorkCenterHistoryEntitySubscriber]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Field, ID, ObjectType } from 'type-graphql'
|
|
2
|
+
import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
HistoryActionColumn,
|
|
6
|
+
HistoryActionType,
|
|
7
|
+
HistoryEntityInterface,
|
|
8
|
+
HistoryOriginalIdColumn
|
|
9
|
+
} from '@operato/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 { WorkCenter, WorkCenterStatus } from './work-center'
|
|
15
|
+
|
|
16
|
+
const ORMCONFIG = config.get('ormconfig', {})
|
|
17
|
+
const DATABASE_TYPE = ORMCONFIG.type
|
|
18
|
+
|
|
19
|
+
@Entity()
|
|
20
|
+
@Index(
|
|
21
|
+
'ix_work-center_history_0',
|
|
22
|
+
(workCenterHistory: WorkCenterHistory) => [workCenterHistory.originalId, workCenterHistory.version],
|
|
23
|
+
{ unique: true }
|
|
24
|
+
)
|
|
25
|
+
@Index(
|
|
26
|
+
'ix_work-center_history_1',
|
|
27
|
+
(workCenterHistory: WorkCenterHistory) => [
|
|
28
|
+
workCenterHistory.domain,
|
|
29
|
+
workCenterHistory.originalId,
|
|
30
|
+
workCenterHistory.version
|
|
31
|
+
],
|
|
32
|
+
{ unique: true }
|
|
33
|
+
)
|
|
34
|
+
@ObjectType({ description: 'History Entity of WorkCenter' })
|
|
35
|
+
export class WorkCenterHistory implements HistoryEntityInterface<WorkCenter> {
|
|
36
|
+
@PrimaryGeneratedColumn('uuid')
|
|
37
|
+
@Field(type => ID)
|
|
38
|
+
readonly id: string
|
|
39
|
+
|
|
40
|
+
@Column({ nullable: true, default: 1 })
|
|
41
|
+
@Field({ nullable: true })
|
|
42
|
+
version?: number = 1
|
|
43
|
+
|
|
44
|
+
@ManyToOne(type => Domain)
|
|
45
|
+
@Field(type => Domain)
|
|
46
|
+
domain?: Domain
|
|
47
|
+
|
|
48
|
+
@RelationId((workCenter: WorkCenter) => workCenter.domain)
|
|
49
|
+
domainId?: string
|
|
50
|
+
|
|
51
|
+
@Column()
|
|
52
|
+
@Field()
|
|
53
|
+
name: string
|
|
54
|
+
|
|
55
|
+
@Column({ nullable: true })
|
|
56
|
+
@Field({ nullable: true })
|
|
57
|
+
description?: string
|
|
58
|
+
|
|
59
|
+
@Column({ nullable: true })
|
|
60
|
+
@Field({ nullable: true })
|
|
61
|
+
active?: boolean
|
|
62
|
+
|
|
63
|
+
@Column({ nullable: true })
|
|
64
|
+
@Field({ nullable: true })
|
|
65
|
+
state?: WorkCenterStatus
|
|
66
|
+
|
|
67
|
+
@Column({ nullable: true })
|
|
68
|
+
@Field({ nullable: true })
|
|
69
|
+
params?: string
|
|
70
|
+
|
|
71
|
+
@Column({ nullable: true })
|
|
72
|
+
@Field({ nullable: true })
|
|
73
|
+
createdAt?: Date
|
|
74
|
+
|
|
75
|
+
@Column({ nullable: true })
|
|
76
|
+
@Field({ nullable: true })
|
|
77
|
+
updatedAt?: Date
|
|
78
|
+
|
|
79
|
+
@Column({ nullable: true })
|
|
80
|
+
@Field({ nullable: true })
|
|
81
|
+
deletedAt?: Date
|
|
82
|
+
|
|
83
|
+
@ManyToOne(type => User, { nullable: true })
|
|
84
|
+
@Field(type => User, { nullable: true })
|
|
85
|
+
creator?: User
|
|
86
|
+
|
|
87
|
+
@RelationId((workCenter: WorkCenter) => workCenter.creator)
|
|
88
|
+
creatorId?: string
|
|
89
|
+
|
|
90
|
+
@ManyToOne(type => User, { nullable: true })
|
|
91
|
+
@Field(type => User, { nullable: true })
|
|
92
|
+
updater?: User
|
|
93
|
+
|
|
94
|
+
@RelationId((workCenter: WorkCenter) => workCenter.updater)
|
|
95
|
+
updaterId?: string
|
|
96
|
+
|
|
97
|
+
@Field(type => String, { nullable: true })
|
|
98
|
+
thumbnail?: string
|
|
99
|
+
|
|
100
|
+
@HistoryOriginalIdColumn()
|
|
101
|
+
public originalId!: string
|
|
102
|
+
|
|
103
|
+
@HistoryActionColumn({
|
|
104
|
+
nullable: false,
|
|
105
|
+
type:
|
|
106
|
+
DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
107
|
+
? 'enum'
|
|
108
|
+
: DATABASE_TYPE == 'oracle'
|
|
109
|
+
? 'varchar2'
|
|
110
|
+
: DATABASE_TYPE == 'mssql'
|
|
111
|
+
? 'nvarchar'
|
|
112
|
+
: 'varchar',
|
|
113
|
+
enum:
|
|
114
|
+
DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
|
|
115
|
+
? HistoryActionType
|
|
116
|
+
: undefined,
|
|
117
|
+
length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
|
|
118
|
+
})
|
|
119
|
+
public action!: HistoryActionType
|
|
120
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
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 { WorkCenter } from './work-center'
|
|
7
|
+
import { NewWorkCenter, WorkCenterPatch } from './work-center-type'
|
|
8
|
+
|
|
9
|
+
@Resolver(WorkCenter)
|
|
10
|
+
export class WorkCenterMutation {
|
|
11
|
+
@Directive('@transaction')
|
|
12
|
+
@Mutation(returns => WorkCenter, { description: 'To create new WorkCenter' })
|
|
13
|
+
async createWorkCenter(@Arg('workCenter') workCenter: NewWorkCenter, @Ctx() context: ResolverContext): Promise<WorkCenter> {
|
|
14
|
+
const { domain, user, tx } = context.state
|
|
15
|
+
|
|
16
|
+
const result = await tx.getRepository(WorkCenter).save({
|
|
17
|
+
...workCenter,
|
|
18
|
+
domain,
|
|
19
|
+
creator: user,
|
|
20
|
+
updater: user
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
if (workCenter.thumbnail) {
|
|
24
|
+
await createAttachment(
|
|
25
|
+
null,
|
|
26
|
+
{
|
|
27
|
+
attachment: {
|
|
28
|
+
file: workCenter.thumbnail,
|
|
29
|
+
refType: WorkCenter.name,
|
|
30
|
+
refBy: result.id
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
context
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Directive('@transaction')
|
|
41
|
+
@Mutation(returns => WorkCenter, { description: 'To modify WorkCenter information' })
|
|
42
|
+
async updateWorkCenter(
|
|
43
|
+
@Arg('id') id: string,
|
|
44
|
+
@Arg('patch') patch: WorkCenterPatch,
|
|
45
|
+
@Ctx() context: ResolverContext
|
|
46
|
+
): Promise<WorkCenter> {
|
|
47
|
+
const { domain, user, tx } = context.state
|
|
48
|
+
|
|
49
|
+
const repository = tx.getRepository(WorkCenter)
|
|
50
|
+
const workCenter = await repository.findOne({
|
|
51
|
+
where: { domain: { id: domain.id }, id }
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const result = await repository.save({
|
|
55
|
+
...workCenter,
|
|
56
|
+
...patch,
|
|
57
|
+
updater: user
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
if (patch.thumbnail) {
|
|
61
|
+
await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
|
|
62
|
+
await createAttachment(
|
|
63
|
+
null,
|
|
64
|
+
{
|
|
65
|
+
attachment: {
|
|
66
|
+
file: patch.thumbnail,
|
|
67
|
+
refType: WorkCenter.name,
|
|
68
|
+
refBy: result.id
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
context
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return result
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@Directive('@transaction')
|
|
79
|
+
@Mutation(returns => [WorkCenter], { description: "To modify multiple WorkCenters' information" })
|
|
80
|
+
async updateMultipleWorkCenter(
|
|
81
|
+
@Arg('patches', type => [WorkCenterPatch]) patches: WorkCenterPatch[],
|
|
82
|
+
@Ctx() context: ResolverContext
|
|
83
|
+
): Promise<WorkCenter[]> {
|
|
84
|
+
const { domain, user, tx } = context.state
|
|
85
|
+
|
|
86
|
+
let results = []
|
|
87
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
88
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
89
|
+
const workCenterRepo = tx.getRepository(WorkCenter)
|
|
90
|
+
|
|
91
|
+
if (_createRecords.length > 0) {
|
|
92
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
93
|
+
const newRecord = _createRecords[i]
|
|
94
|
+
|
|
95
|
+
const result = await workCenterRepo.save({
|
|
96
|
+
...newRecord,
|
|
97
|
+
domain,
|
|
98
|
+
creator: user,
|
|
99
|
+
updater: user
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
if (newRecord.thumbnail) {
|
|
103
|
+
await createAttachment(
|
|
104
|
+
null,
|
|
105
|
+
{
|
|
106
|
+
attachment: {
|
|
107
|
+
file: newRecord.thumbnail,
|
|
108
|
+
refType: WorkCenter.name,
|
|
109
|
+
refBy: result.id
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
context
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
results.push({ ...result, cuFlag: '+' })
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (_updateRecords.length > 0) {
|
|
121
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
122
|
+
const updateRecord = _updateRecords[i]
|
|
123
|
+
const workCenter = await workCenterRepo.findOneBy({ id: updateRecord.id })
|
|
124
|
+
|
|
125
|
+
const result = await workCenterRepo.save({
|
|
126
|
+
...workCenter,
|
|
127
|
+
...updateRecord,
|
|
128
|
+
updater: user
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
if (updateRecord.thumbnail) {
|
|
132
|
+
await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
|
|
133
|
+
await createAttachment(
|
|
134
|
+
null,
|
|
135
|
+
{
|
|
136
|
+
attachment: {
|
|
137
|
+
file: updateRecord.thumbnail,
|
|
138
|
+
refType: WorkCenter.name,
|
|
139
|
+
refBy: result.id
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
context
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return results
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@Directive('@transaction')
|
|
154
|
+
@Mutation(returns => Boolean, { description: 'To delete WorkCenter' })
|
|
155
|
+
async deleteWorkCenter(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
156
|
+
const { domain, tx } = context.state
|
|
157
|
+
|
|
158
|
+
await tx.getRepository(WorkCenter).delete({ domain: { id: domain.id }, id })
|
|
159
|
+
await deleteAttachmentsByRef(null, { refBys: [id] }, context)
|
|
160
|
+
|
|
161
|
+
return true
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Directive('@transaction')
|
|
165
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple WorkCenters' })
|
|
166
|
+
async deleteWorkCenters(
|
|
167
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
168
|
+
@Ctx() context: ResolverContext
|
|
169
|
+
): Promise<boolean> {
|
|
170
|
+
const { domain, tx } = context.state
|
|
171
|
+
|
|
172
|
+
await tx.getRepository(WorkCenter).delete({
|
|
173
|
+
domain: { id: domain.id },
|
|
174
|
+
id: In(ids)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
await deleteAttachmentsByRef(null, { refBys: ids }, context)
|
|
178
|
+
|
|
179
|
+
return true
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@Directive('@transaction')
|
|
183
|
+
@Mutation(returns => Boolean, { description: 'To import multiple WorkCenters' })
|
|
184
|
+
async importWorkCenters(
|
|
185
|
+
@Arg('workCenters', type => [WorkCenterPatch]) workCenters: WorkCenterPatch[],
|
|
186
|
+
@Ctx() context: ResolverContext
|
|
187
|
+
): Promise<boolean> {
|
|
188
|
+
const { domain, tx } = context.state
|
|
189
|
+
|
|
190
|
+
await Promise.all(
|
|
191
|
+
workCenters.map(async (workCenter: WorkCenterPatch) => {
|
|
192
|
+
const createdWorkCenter: WorkCenter = await tx.getRepository(WorkCenter).save({ domain, ...workCenter })
|
|
193
|
+
})
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
return true
|
|
197
|
+
}
|
|
198
|
+
}
|