rez_core 2.2.17 → 2.2.18
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/module/workflow/service/action.service.js +21 -7
- package/dist/module/workflow/service/action.service.js.map +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js +36 -16
- package/dist/module/workflow/service/populate-workflow.service.js.map +1 -1
- package/dist/module/workflow/service/workflow.service.js +15 -19
- package/dist/module/workflow/service/workflow.service.js.map +1 -1
- package/dist/module/workflow/workflow.module.js +10 -0
- package/dist/module/workflow/workflow.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/workflow/service/action.service.ts +30 -19
- package/src/module/workflow/service/populate-workflow.service.ts +64 -20
- package/src/module/workflow/service/workflow.service.ts +24 -30
- package/src/module/workflow/workflow.module.ts +10 -0
package/package.json
CHANGED
|
@@ -41,37 +41,26 @@ export class ActionService extends EntityServiceImpl {
|
|
|
41
41
|
manager?: EntityManager | null,
|
|
42
42
|
appcode?: string,
|
|
43
43
|
): Promise<any> {
|
|
44
|
-
|
|
44
|
+
const actionData = entityData as any;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
loggedInUser,
|
|
49
|
-
manager,
|
|
50
|
-
appcode,
|
|
51
|
-
);
|
|
46
|
+
// Step 1: Create main action entity
|
|
47
|
+
const action = await super.createEntity(entityData, loggedInUser);
|
|
52
48
|
|
|
53
|
-
// stage mapping
|
|
54
|
-
|
|
49
|
+
// Step 2: Create stage mapping
|
|
50
|
+
const stageActionMapping = {
|
|
55
51
|
action_id: action.id,
|
|
56
52
|
stage_id: actionData.stage_id,
|
|
57
53
|
entity_type: 'STGM',
|
|
58
54
|
} as any;
|
|
59
55
|
|
|
60
|
-
|
|
56
|
+
const stageActionMappingData = await super.createEntity(
|
|
61
57
|
stageActionMapping,
|
|
62
58
|
loggedInUser,
|
|
63
|
-
manager,
|
|
64
|
-
appcode,
|
|
65
59
|
);
|
|
66
60
|
|
|
67
|
-
//
|
|
61
|
+
// Step 3: Template mapping (existing)
|
|
68
62
|
if (Array.isArray(actionData.template) && actionData.template.length > 0) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
for (let i = 0; i < templates.length; i++) {
|
|
72
|
-
const templateCode = templates[i];
|
|
73
|
-
|
|
74
|
-
// Create Action-Template Mapping
|
|
63
|
+
for (const templateCode of actionData.template) {
|
|
75
64
|
const actionTemplateMapping = {
|
|
76
65
|
stg_act_mapping_id: stageActionMappingData.id,
|
|
77
66
|
template_code: templateCode,
|
|
@@ -84,6 +73,28 @@ export class ActionService extends EntityServiceImpl {
|
|
|
84
73
|
manager,
|
|
85
74
|
appcode,
|
|
86
75
|
);
|
|
76
|
+
|
|
77
|
+
// ➕ Step 4: Resource mapping for template
|
|
78
|
+
const resourceMapping = {
|
|
79
|
+
template_code: templateCode,
|
|
80
|
+
type: 'template',
|
|
81
|
+
entity_type: 'ARMS',
|
|
82
|
+
} as any;
|
|
83
|
+
|
|
84
|
+
await super.createEntity(resourceMapping, loggedInUser);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ➕ Step 5: Resource mapping for form (if form is sent)
|
|
89
|
+
if (actionData.form && actionData.form.length > 0) {
|
|
90
|
+
for (const formId of actionData.form) {
|
|
91
|
+
const resourceMapping = {
|
|
92
|
+
form_id: formId,
|
|
93
|
+
type: 'form',
|
|
94
|
+
entity_type: 'ARMS',
|
|
95
|
+
} as any;
|
|
96
|
+
|
|
97
|
+
await super.createEntity(resourceMapping, loggedInUser);
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ActionCategory } from './../entity/action-category.entity';
|
|
1
2
|
import { DataSource } from 'typeorm';
|
|
2
3
|
import { PopulateMetaService } from './../../meta/service/populate-meta.service';
|
|
3
4
|
import { Inject, Injectable } from '@nestjs/common';
|
|
@@ -80,6 +81,29 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
80
81
|
// }
|
|
81
82
|
|
|
82
83
|
async populateWorkflowData(organization_id: number, loggedInUser: UserData) {
|
|
84
|
+
const defaultEntity = await this.dataSource.query(
|
|
85
|
+
`SELECT * FROM eth_entity WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1 AND entity_type = 'ENT'`,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const defaultEntityData = defaultEntity[0];
|
|
89
|
+
|
|
90
|
+
defaultEntityData.organization_id = organization_id;
|
|
91
|
+
defaultEntityData.level_id = organization_id;
|
|
92
|
+
|
|
93
|
+
await this.dataSource.query(
|
|
94
|
+
`INSERT INTO eth_entity (entity_type, name, status, code, enterprise_id, organization_id, level_id, level_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
95
|
+
[
|
|
96
|
+
defaultEntityData.entity_type,
|
|
97
|
+
defaultEntityData.name,
|
|
98
|
+
defaultEntityData.status,
|
|
99
|
+
defaultEntityData.code,
|
|
100
|
+
defaultEntityData.enterprise_id,
|
|
101
|
+
organization_id,
|
|
102
|
+
organization_id,
|
|
103
|
+
defaultEntityData.level_type,
|
|
104
|
+
],
|
|
105
|
+
);
|
|
106
|
+
|
|
83
107
|
const workflowTables = [
|
|
84
108
|
{ table: 'cr_workflow', entityType: 'WRFW', service: 'workflowService' },
|
|
85
109
|
{
|
|
@@ -99,7 +123,7 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
99
123
|
const factoryData = await Promise.all(
|
|
100
124
|
workflowTables.map(getAllFactoryData),
|
|
101
125
|
);
|
|
102
|
-
const [workflows, stageGroups, stages
|
|
126
|
+
const [workflows, stageGroups, stages] = factoryData;
|
|
103
127
|
|
|
104
128
|
// === 1. Workflow mapping
|
|
105
129
|
const workflowIdMap: Record<number, number> = {};
|
|
@@ -157,28 +181,48 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
157
181
|
);
|
|
158
182
|
stageIdMap[id] = newStage.id;
|
|
159
183
|
stageToStageGroupMap[id] = stage_group_id; // maintain
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// === 4. Action mapping — point to stage, stageGroup, workflow correctly
|
|
163
|
-
for (const row of actions) {
|
|
164
|
-
const { id, stage_id, created_date, modified_date, ...rest } = row;
|
|
165
184
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
// step 1 find old stage_id in stage_action_mapper and get all actions_ids
|
|
186
|
+
// step 2 search action in cr_wf_action table with those action_ids
|
|
187
|
+
// step 3 create new action with new stage_id and new workflow_id
|
|
188
|
+
// step 4 save new action
|
|
170
189
|
|
|
171
|
-
await this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
stage_id: newStageId,
|
|
175
|
-
workflow_id: newWorkflowId,
|
|
176
|
-
organization_id,
|
|
177
|
-
level_id: organization_id,
|
|
178
|
-
entity_type: 'ACTN',
|
|
179
|
-
},
|
|
180
|
-
loggedInUser,
|
|
190
|
+
const stageIds = await this.dataSource.query(
|
|
191
|
+
`SELECT action_id FROM cr_wf_stage_action_mapping WHERE stage_id = ?`,
|
|
192
|
+
[id],
|
|
181
193
|
);
|
|
194
|
+
|
|
195
|
+
const actionIds = stageIds.map((item) => item.action_id);
|
|
196
|
+
|
|
197
|
+
let actions = [];
|
|
198
|
+
if (actionIds.length > 0) {
|
|
199
|
+
actions = await this.dataSource.query(
|
|
200
|
+
`SELECT * FROM cr_wf_action WHERE id IN (?)`,
|
|
201
|
+
[actionIds],
|
|
202
|
+
);
|
|
203
|
+
} else {
|
|
204
|
+
// No actions to query
|
|
205
|
+
actions = [];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// === 4. Action mapping — point to stage, stageGroup, workflow correctly
|
|
209
|
+
for (const row of actions as any[]) {
|
|
210
|
+
const { id, created_date, modified_date, workflow_id, ...rest } = row;
|
|
211
|
+
|
|
212
|
+
const newWorkflowId = workflowIdMap[workflow_id];
|
|
213
|
+
|
|
214
|
+
await this.actionService.createEntity(
|
|
215
|
+
{
|
|
216
|
+
...rest,
|
|
217
|
+
stage_id: newStage.id,
|
|
218
|
+
workflow_id: newWorkflowId,
|
|
219
|
+
organization_id,
|
|
220
|
+
level_id: organization_id,
|
|
221
|
+
entity_type: 'ACTN',
|
|
222
|
+
},
|
|
223
|
+
loggedInUser,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
182
226
|
}
|
|
183
227
|
|
|
184
228
|
return {
|
|
@@ -86,38 +86,32 @@ export class WorkflowService extends EntityServiceImpl {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
const isDefault = [true, 1, 'true'].includes(
|
|
90
|
+
(entityData as any).is_default,
|
|
91
|
+
);
|
|
89
92
|
// Handle is_default uniqueness logic within same level
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
if (isDefault) {
|
|
94
|
+
await this.dataSource
|
|
95
|
+
.createQueryBuilder()
|
|
96
|
+
.update(Workflow)
|
|
97
|
+
.set({ is_default: 0 })
|
|
98
|
+
.where(
|
|
99
|
+
'level_id = :level_id AND level_type = :level_type AND id != :currentId',
|
|
100
|
+
{
|
|
101
|
+
level_id,
|
|
102
|
+
level_type,
|
|
103
|
+
currentId: workflowId,
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
.execute();
|
|
107
|
+
|
|
108
|
+
// Update cr_workflow_level_mapping to point to the new workflow
|
|
109
|
+
await this.dataSource.query(
|
|
110
|
+
`UPDATE cr_workflow_level_mapping
|
|
111
|
+
SET workflow_id = ?
|
|
112
|
+
WHERE mapped_level_id = ? AND mapped_level_type = ?`,
|
|
113
|
+
[workflowId, level_id, level_type],
|
|
98
114
|
);
|
|
99
|
-
|
|
100
|
-
if (oldDefault?.length) {
|
|
101
|
-
const oldWorkflowId = oldDefault[0].id;
|
|
102
|
-
|
|
103
|
-
// Step 2: Update old workflow to is_default = 0
|
|
104
|
-
await this.dataSource
|
|
105
|
-
.createQueryBuilder()
|
|
106
|
-
.update(Workflow)
|
|
107
|
-
.set({ is_default: 0 })
|
|
108
|
-
.where('id = :id', { id: oldWorkflowId })
|
|
109
|
-
.execute();
|
|
110
|
-
|
|
111
|
-
// Step 3: Update cr_workflow_level_mapping to point to new workflowId
|
|
112
|
-
await this.dataSource.query(
|
|
113
|
-
`
|
|
114
|
-
UPDATE cr_workflow_level_mapping
|
|
115
|
-
SET workflow_id = ?
|
|
116
|
-
WHERE mapped_level_id = ? AND mapped_level_type = ?
|
|
117
|
-
`,
|
|
118
|
-
[workflowId, level_id, level_type],
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
115
|
}
|
|
122
116
|
|
|
123
117
|
// Final update
|
|
@@ -53,6 +53,9 @@ import { FormMasterDataEntity } from './entity/form-master.entity';
|
|
|
53
53
|
import { FormMasterController } from './controller/form-master.controller';
|
|
54
54
|
import { FormMasterService } from './service/form-master.service';
|
|
55
55
|
import { FormMasterRepository } from './repository/form-master.repository';
|
|
56
|
+
import { ActionResourcesMapping } from './entity/action-resources-mapping.entity';
|
|
57
|
+
import { ActionResourcesMappingService } from './service/action-resources-mapping.service';
|
|
58
|
+
import { ActionResourcesMappingController } from './controller/action-resource-mapping.controller';
|
|
56
59
|
|
|
57
60
|
@Module({
|
|
58
61
|
imports: [
|
|
@@ -72,6 +75,7 @@ import { FormMasterRepository } from './repository/form-master.repository';
|
|
|
72
75
|
TaskDataEntity,
|
|
73
76
|
ActionDataEntity,
|
|
74
77
|
FormMasterDataEntity,
|
|
78
|
+
ActionResourcesMapping,
|
|
75
79
|
]),
|
|
76
80
|
EntityModule,
|
|
77
81
|
ListMasterModule,
|
|
@@ -93,6 +97,10 @@ import { FormMasterRepository } from './repository/form-master.repository';
|
|
|
93
97
|
useClass: EntityModificationService,
|
|
94
98
|
},
|
|
95
99
|
{ provide: 'FormMasterService', useClass: FormMasterService },
|
|
100
|
+
{
|
|
101
|
+
provide: 'ActionResourcesMappingService',
|
|
102
|
+
useClass: ActionResourcesMappingService,
|
|
103
|
+
},
|
|
96
104
|
WorkflowListMasterService,
|
|
97
105
|
ActionTemplateMappingService,
|
|
98
106
|
WorkflowRepository,
|
|
@@ -119,6 +127,7 @@ import { FormMasterRepository } from './repository/form-master.repository';
|
|
|
119
127
|
'StageGroupService',
|
|
120
128
|
'EntityModificationService',
|
|
121
129
|
'FormMasterService',
|
|
130
|
+
'ActionResourcesMappingService',
|
|
122
131
|
WorkflowRepository,
|
|
123
132
|
StageGroupRepository,
|
|
124
133
|
StageRepository,
|
|
@@ -138,6 +147,7 @@ import { FormMasterRepository } from './repository/form-master.repository';
|
|
|
138
147
|
ActionCategoryController,
|
|
139
148
|
TaskController,
|
|
140
149
|
FormMasterController,
|
|
150
|
+
ActionResourcesMappingController,
|
|
141
151
|
],
|
|
142
152
|
})
|
|
143
153
|
export class WorkflowModule {}
|