rez_core 2.1.145 → 2.1.148
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/layout_preference/controller/layout_preference.controller.js +2 -2
- package/dist/module/layout_preference/controller/layout_preference.controller.js.map +1 -1
- package/dist/module/layout_preference/entity/layout_preference.entity.d.ts +2 -0
- package/dist/module/layout_preference/entity/layout_preference.entity.js +13 -0
- package/dist/module/layout_preference/entity/layout_preference.entity.js.map +1 -1
- package/dist/module/layout_preference/repository/layout_preference.repository.d.ts +1 -1
- package/dist/module/layout_preference/repository/layout_preference.repository.js +4 -2
- package/dist/module/layout_preference/repository/layout_preference.repository.js.map +1 -1
- package/dist/module/layout_preference/service/layout_preference.service.d.ts +1 -1
- package/dist/module/layout_preference/service/layout_preference.service.js +10 -4
- package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
- package/dist/module/meta/controller/media.controller.d.ts +1 -1
- package/dist/module/meta/controller/media.controller.js +1 -1
- package/dist/module/meta/controller/media.controller.js.map +1 -1
- package/dist/module/workflow/controller/action-category.controller.d.ts +8 -0
- package/dist/module/workflow/controller/action-category.controller.js +45 -0
- package/dist/module/workflow/controller/action-category.controller.js.map +1 -0
- package/dist/module/workflow/controller/action.controller.d.ts +1 -1
- package/dist/module/workflow/controller/action.controller.js +3 -3
- package/dist/module/workflow/controller/action.controller.js.map +1 -1
- package/dist/module/workflow/controller/comm-template.controller.d.ts +2 -2
- package/dist/module/workflow/controller/comm-template.controller.js +4 -4
- package/dist/module/workflow/controller/comm-template.controller.js.map +1 -1
- package/dist/module/workflow/controller/workflow-meta.controller.d.ts +9 -0
- package/dist/module/workflow/controller/workflow-meta.controller.js +63 -0
- package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -0
- package/dist/module/workflow/controller/workflow.controller.d.ts +9 -1
- package/dist/module/workflow/controller/workflow.controller.js +17 -2
- package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
- package/dist/module/workflow/entity/action-category.entity.d.ts +1 -0
- package/dist/module/workflow/entity/action-category.entity.js +4 -0
- package/dist/module/workflow/entity/action-category.entity.js.map +1 -1
- package/dist/module/workflow/entity/action.entity.d.ts +2 -2
- package/dist/module/workflow/entity/action.entity.js +3 -3
- package/dist/module/workflow/entity/action.entity.js.map +1 -1
- package/dist/module/workflow/entity/comm-template.entity.d.ts +5 -0
- package/dist/module/workflow/entity/comm-template.entity.js +21 -1
- package/dist/module/workflow/entity/comm-template.entity.js.map +1 -1
- package/dist/module/workflow/entity/stage-movement-data.entity.d.ts +2 -0
- package/dist/module/workflow/entity/stage-movement-data.entity.js +8 -0
- package/dist/module/workflow/entity/stage-movement-data.entity.js.map +1 -1
- package/dist/module/workflow/entity/template-attach-mapper.entity.d.ts +11 -0
- package/dist/module/workflow/entity/template-attach-mapper.entity.js +54 -0
- package/dist/module/workflow/entity/template-attach-mapper.entity.js.map +1 -0
- package/dist/module/workflow/repository/comm-template.repository.d.ts +8 -2
- package/dist/module/workflow/repository/comm-template.repository.js +37 -6
- package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
- package/dist/module/workflow/service/action-category.service.d.ts +5 -0
- package/dist/module/workflow/service/action-category.service.js +23 -1
- package/dist/module/workflow/service/action-category.service.js.map +1 -1
- package/dist/module/workflow/service/action.service.d.ts +1 -1
- package/dist/module/workflow/service/action.service.js +78 -26
- package/dist/module/workflow/service/action.service.js.map +1 -1
- package/dist/module/workflow/service/comm-template.service.d.ts +4 -1
- package/dist/module/workflow/service/comm-template.service.js +38 -1
- package/dist/module/workflow/service/comm-template.service.js.map +1 -1
- package/dist/module/workflow/service/populate-workflow.service.d.ts +21 -0
- package/dist/module/workflow/service/populate-workflow.service.js +124 -0
- package/dist/module/workflow/service/populate-workflow.service.js.map +1 -0
- package/dist/module/workflow/service/workflow-list-master.service.js +3 -3
- package/dist/module/workflow/service/workflow-meta.service.d.ts +9 -0
- package/dist/module/workflow/service/workflow-meta.service.js +81 -0
- package/dist/module/workflow/service/workflow-meta.service.js.map +1 -0
- package/dist/module/workflow/workflow.module.js +41 -26
- 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/layout_preference/controller/layout_preference.controller.ts +4 -2
- package/src/module/layout_preference/entity/layout_preference.entity.ts +11 -0
- package/src/module/layout_preference/repository/layout_preference.repository.ts +6 -2
- package/src/module/layout_preference/service/layout_preference.service.ts +24 -6
- package/src/module/meta/controller/media.controller.ts +5 -7
- package/src/module/workflow/controller/action-category.controller.ts +35 -0
- package/src/module/workflow/controller/action.controller.ts +2 -2
- package/src/module/workflow/controller/comm-template.controller.ts +5 -4
- package/src/module/workflow/controller/workflow-meta.controller.ts +52 -0
- package/src/module/workflow/controller/workflow.controller.ts +14 -0
- package/src/module/workflow/entity/action-category.entity.ts +3 -0
- package/src/module/workflow/entity/action.entity.ts +3 -3
- package/src/module/workflow/entity/comm-template.entity.ts +18 -1
- package/src/module/workflow/entity/stage-movement-data.entity.ts +6 -0
- package/src/module/workflow/entity/template-attach-mapper.entity.ts +30 -0
- package/src/module/workflow/repository/comm-template.repository.ts +58 -5
- package/src/module/workflow/service/action-category.service.ts +26 -1
- package/src/module/workflow/service/action-template-mapping.service.ts +1 -1
- package/src/module/workflow/service/action.service.ts +103 -24
- package/src/module/workflow/service/comm-template.service.ts +54 -1
- package/src/module/workflow/service/populate-workflow.service.ts +189 -0
- package/src/module/workflow/service/workflow-list-master.service.ts +3 -3
- package/src/module/workflow/service/workflow-meta.service.ts +98 -0
- package/src/module/workflow/workflow.module.ts +41 -27
|
@@ -37,8 +37,6 @@ export class ActionService extends EntityServiceImpl {
|
|
|
37
37
|
manager?: EntityManager | null,
|
|
38
38
|
appcode?: string,
|
|
39
39
|
): Promise<any> {
|
|
40
|
-
console.log('entityData', entityData);
|
|
41
|
-
|
|
42
40
|
let actionData = entityData as any;
|
|
43
41
|
|
|
44
42
|
let action = await super.createEntity(
|
|
@@ -196,7 +194,7 @@ export class ActionService extends EntityServiceImpl {
|
|
|
196
194
|
}
|
|
197
195
|
const result = await this.dataSource.query(
|
|
198
196
|
`
|
|
199
|
-
SELECT name,
|
|
197
|
+
SELECT name, id
|
|
200
198
|
FROM cr_list_master_items
|
|
201
199
|
WHERE listtype = ? AND organization_id = ?
|
|
202
200
|
`,
|
|
@@ -205,38 +203,119 @@ export class ActionService extends EntityServiceImpl {
|
|
|
205
203
|
|
|
206
204
|
// Format as array of key-value pairs
|
|
207
205
|
return result.map((row: any) => ({
|
|
208
|
-
label: row.
|
|
209
|
-
value: row.
|
|
206
|
+
label: row.name,
|
|
207
|
+
value: row.id,
|
|
210
208
|
}));
|
|
211
209
|
}
|
|
212
210
|
|
|
213
|
-
async getActions(loggedInUser: UserData,
|
|
211
|
+
async getActions(loggedInUser: UserData, stage_id: number) {
|
|
214
212
|
const { organization_id } = loggedInUser;
|
|
215
213
|
|
|
216
|
-
|
|
214
|
+
// Step 1: Get all action_ids for the provided stage_id
|
|
215
|
+
const stageActions = await this.dataSource.query(
|
|
217
216
|
`
|
|
218
|
-
SELECT
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
FROM cr_wf_action a
|
|
217
|
+
SELECT id, action_id
|
|
218
|
+
FROM cr_wf_stage_action_mapping
|
|
219
|
+
WHERE stage_id = ?
|
|
220
|
+
`,
|
|
221
|
+
[stage_id],
|
|
222
|
+
);
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
ON ac.id = a.action_cat_id
|
|
224
|
+
if (!stageActions?.length) return [];
|
|
228
225
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
AND ar.listtype = 'ACRQ'
|
|
232
|
-
AND ar.organization_id = ?
|
|
226
|
+
const actionIds = stageActions.map((sa) => sa.action_id);
|
|
227
|
+
const mappingIds = stageActions.map((sa) => sa.id);
|
|
233
228
|
|
|
234
|
-
|
|
235
|
-
|
|
229
|
+
// Step 2: Get template codes with mapping IDs
|
|
230
|
+
const templateMappings = await this.dataSource.query(
|
|
231
|
+
`
|
|
232
|
+
SELECT stg_act_mapping_id, template_code
|
|
233
|
+
FROM cr_wf_action_template_mapping
|
|
234
|
+
WHERE stg_act_mapping_id IN (${mappingIds.map(() => '?').join(',')})
|
|
236
235
|
`,
|
|
237
|
-
|
|
236
|
+
mappingIds,
|
|
238
237
|
);
|
|
239
238
|
|
|
240
|
-
|
|
239
|
+
const templateCodes = templateMappings.map((tm) => tm.template_code);
|
|
240
|
+
|
|
241
|
+
// Step 3: Fetch template names from cr_wf_comm_template
|
|
242
|
+
const templateCodeToName: Record<string, string> = {};
|
|
243
|
+
|
|
244
|
+
if (templateCodes.length > 0) {
|
|
245
|
+
const templates = await this.dataSource
|
|
246
|
+
.createQueryBuilder()
|
|
247
|
+
.select(['t.code AS code', 't.name AS name'])
|
|
248
|
+
.from('cr_wf_comm_template', 't')
|
|
249
|
+
.where('t.code IN (:...codes)', { codes: templateCodes })
|
|
250
|
+
.andWhere('t.organization_id = :orgId', { orgId: organization_id })
|
|
251
|
+
.getRawMany();
|
|
252
|
+
|
|
253
|
+
templates.forEach((tpl) => {
|
|
254
|
+
templateCodeToName[tpl.code] = tpl.name;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Step 4: Build map of mapping_id → template names
|
|
259
|
+
const mappingIdToTemplates: Record<number, string[]> = {};
|
|
260
|
+
|
|
261
|
+
for (const tm of templateMappings) {
|
|
262
|
+
const mappingId = tm.stg_act_mapping_id;
|
|
263
|
+
const name = templateCodeToName[tm.template_code];
|
|
264
|
+
if (name) {
|
|
265
|
+
if (!mappingIdToTemplates[mappingId]) {
|
|
266
|
+
mappingIdToTemplates[mappingId] = [];
|
|
267
|
+
}
|
|
268
|
+
mappingIdToTemplates[mappingId].push(name);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Step 5: Build action_id → template names using mappingIdToTemplates + stageActions
|
|
273
|
+
const actionIdToTemplates: Record<number, string[]> = {};
|
|
274
|
+
|
|
275
|
+
for (const sa of stageActions) {
|
|
276
|
+
const mappingId = sa.id;
|
|
277
|
+
const templates = mappingIdToTemplates[mappingId];
|
|
278
|
+
if (templates?.length) {
|
|
279
|
+
if (!actionIdToTemplates[sa.action_id]) {
|
|
280
|
+
actionIdToTemplates[sa.action_id] = [];
|
|
281
|
+
}
|
|
282
|
+
actionIdToTemplates[sa.action_id].push(...templates);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Step 6: Fetch action details
|
|
287
|
+
const actionResults = await this.dataSource
|
|
288
|
+
.createQueryBuilder()
|
|
289
|
+
.select([
|
|
290
|
+
'a.id AS id',
|
|
291
|
+
'a.name AS action_name',
|
|
292
|
+
'ac.name AS action_category',
|
|
293
|
+
'ar.name AS action_requirement',
|
|
294
|
+
])
|
|
295
|
+
.from('cr_wf_action', 'a')
|
|
296
|
+
.leftJoin('cr_wf_action_category', 'ac', 'ac.id = a.action_cat_id')
|
|
297
|
+
.leftJoin(
|
|
298
|
+
'cr_list_master_items',
|
|
299
|
+
'ar',
|
|
300
|
+
`ar.id = a.action_requirement AND ar.listtype = 'ACRQ' AND ar.organization_id = :orgId`,
|
|
301
|
+
{ orgId: organization_id },
|
|
302
|
+
)
|
|
303
|
+
.where('a.organization_id = :orgId', { orgId: organization_id })
|
|
304
|
+
.andWhere('a.id IN (:...actionIds)', { actionIds })
|
|
305
|
+
.getRawMany();
|
|
306
|
+
|
|
307
|
+
// Step 7: Enrich result with template field
|
|
308
|
+
const enrichedResult = actionResults.map((row) => {
|
|
309
|
+
const actionId = Number(row.id); // Ensure numeric ID match
|
|
310
|
+
const templates = actionIdToTemplates[actionId] || [];
|
|
311
|
+
const uniqueTemplates = [...new Set(templates)]; // remove duplicates
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
...row,
|
|
315
|
+
template: uniqueTemplates.join(', '),
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
return enrichedResult;
|
|
241
320
|
}
|
|
242
321
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { CommTemplateRepository } from '../repository/comm-template.repository';
|
|
3
3
|
import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
|
|
4
|
+
import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
|
|
5
|
+
import { UserData } from 'src/module/user/entity/user.entity';
|
|
4
6
|
|
|
5
7
|
@Injectable()
|
|
6
8
|
export class CommTemplateService extends EntityServiceImpl {
|
|
@@ -8,6 +10,57 @@ export class CommTemplateService extends EntityServiceImpl {
|
|
|
8
10
|
super();
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
async createEntity(entityData: any, loggedInUser: any): Promise<any> {
|
|
14
|
+
const { attachments, ...templateData } = entityData;
|
|
15
|
+
|
|
16
|
+
const tempData = await super.createEntity(templateData, loggedInUser);
|
|
17
|
+
|
|
18
|
+
// attachment mapper create and update
|
|
19
|
+
if (attachments && attachments.length > 0) {
|
|
20
|
+
const attachmentEntities = attachments.map((attachment) => ({
|
|
21
|
+
entity_type: templateData.entity_type,
|
|
22
|
+
template_id: tempData.id,
|
|
23
|
+
media_id: attachment,
|
|
24
|
+
organization_id: loggedInUser.organization_id,
|
|
25
|
+
appcode: loggedInUser.appcode,
|
|
26
|
+
level_id: loggedInUser.level_id,
|
|
27
|
+
level_type: loggedInUser.level_type,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
await this.commTemplateRepository.save(attachmentEntities);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return tempData;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async updateEntity(entityData: any, loggedInUser: UserData): Promise<any> {
|
|
37
|
+
const { attachments, ...templateData } = entityData;
|
|
38
|
+
|
|
39
|
+
const tempData = await super.updateEntity(templateData, loggedInUser);
|
|
40
|
+
|
|
41
|
+
// delete existing mapper
|
|
42
|
+
await this.commTemplateRepository.delete({
|
|
43
|
+
template_id: tempData.id,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// attachment mapper create and update
|
|
47
|
+
if (attachments && attachments.length > 0) {
|
|
48
|
+
const attachmentEntities = attachments.map((attachment) => ({
|
|
49
|
+
entity_type: templateData.entity_type,
|
|
50
|
+
template_id: tempData.id,
|
|
51
|
+
media_id: attachment,
|
|
52
|
+
organization_id: loggedInUser.organization_id,
|
|
53
|
+
appcode: loggedInUser.appcode,
|
|
54
|
+
level_id: loggedInUser.level_id,
|
|
55
|
+
level_type: loggedInUser.level_type,
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
await this.commTemplateRepository.save(attachmentEntities);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return tempData;
|
|
62
|
+
}
|
|
63
|
+
|
|
11
64
|
async getEntityData(
|
|
12
65
|
entityType: string,
|
|
13
66
|
id: number,
|
|
@@ -32,8 +85,8 @@ export class CommTemplateService extends EntityServiceImpl {
|
|
|
32
85
|
);
|
|
33
86
|
|
|
34
87
|
const response = commTemplateData.map((item) => ({
|
|
35
|
-
label: item.name,
|
|
36
88
|
value: item.code,
|
|
89
|
+
name: item.name,
|
|
37
90
|
}));
|
|
38
91
|
|
|
39
92
|
return response;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
import { PopulateMetaService } from './../../meta/service/populate-meta.service';
|
|
3
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
4
|
+
import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
|
|
5
|
+
import { WorkflowService } from './workflow.service';
|
|
6
|
+
import { UserData } from 'src/module/user/entity/user.entity';
|
|
7
|
+
import { StageGroupService } from './stage-group.service';
|
|
8
|
+
import { StageService } from './stage.service';
|
|
9
|
+
import { ActionService } from './action.service';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class PopulateWorkflowService extends EntityServiceImpl {
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly populateMetaService: PopulateMetaService,
|
|
15
|
+
private readonly dataSource: DataSource,
|
|
16
|
+
@Inject('WorkflowService')
|
|
17
|
+
private readonly workflowService: WorkflowService,
|
|
18
|
+
@Inject('StageGroupService')
|
|
19
|
+
private readonly stageGroupService: StageGroupService,
|
|
20
|
+
@Inject('StageService')
|
|
21
|
+
private readonly stageService: StageService,
|
|
22
|
+
@Inject('ActionService')
|
|
23
|
+
private readonly actionService: ActionService,
|
|
24
|
+
) {
|
|
25
|
+
super();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// async populateWorkflowData(organization_id: number, loggedInUser: UserData) {
|
|
29
|
+
// // Define workflow tables
|
|
30
|
+
// const workflowTables = [
|
|
31
|
+
// { table: 'cr_workflow', entityType: 'WRFW', service: 'workflowService' },
|
|
32
|
+
// {
|
|
33
|
+
// table: 'cr_wf_stage_group',
|
|
34
|
+
// entityType: 'STGP',
|
|
35
|
+
// service: 'stageGroupService',
|
|
36
|
+
// },
|
|
37
|
+
// { table: 'cr_wf_stage', entityType: 'STG', service: 'stageService' },
|
|
38
|
+
// { table: 'cr_wf_action', entityType: 'ACTN', service: 'actionService' },
|
|
39
|
+
// ];
|
|
40
|
+
|
|
41
|
+
// const getAllFactoryData = async (table: { table: string }) => {
|
|
42
|
+
// return this.dataSource.query(
|
|
43
|
+
// `SELECT * FROM ${table.table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
|
|
44
|
+
// );
|
|
45
|
+
// };
|
|
46
|
+
|
|
47
|
+
// const factoryData = await Promise.all(
|
|
48
|
+
// workflowTables.map((table) => getAllFactoryData(table)),
|
|
49
|
+
// );
|
|
50
|
+
|
|
51
|
+
// // Step 1: Insert workflow metadata
|
|
52
|
+
// for (let i = 0; i < workflowTables.length; i++) {
|
|
53
|
+
// const table = workflowTables[i];
|
|
54
|
+
// const data = factoryData[i];
|
|
55
|
+
|
|
56
|
+
// if (!data.length) continue;
|
|
57
|
+
|
|
58
|
+
// // Clean and transform data for insertion
|
|
59
|
+
// const transformedData = data.map((row) => {
|
|
60
|
+
// const { id, created_date, modified_date, ...rest } = row;
|
|
61
|
+
// return {
|
|
62
|
+
// ...rest,
|
|
63
|
+
// organization_id: organization_id,
|
|
64
|
+
// level_id: organization_id,
|
|
65
|
+
// entity_type: table.entityType,
|
|
66
|
+
// };
|
|
67
|
+
// });
|
|
68
|
+
|
|
69
|
+
// const service = this[table.service];
|
|
70
|
+
|
|
71
|
+
// for (const record of transformedData) {
|
|
72
|
+
// await service.createEntity(record, loggedInUser);
|
|
73
|
+
// }
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
// return {
|
|
77
|
+
// message: 'Workflow data populated successfully',
|
|
78
|
+
// status: 'success',
|
|
79
|
+
// };
|
|
80
|
+
// }
|
|
81
|
+
|
|
82
|
+
async populateWorkflowData(organization_id: number, loggedInUser: UserData) {
|
|
83
|
+
const workflowTables = [
|
|
84
|
+
{ table: 'cr_workflow', entityType: 'WRFW', service: 'workflowService' },
|
|
85
|
+
{
|
|
86
|
+
table: 'cr_wf_stage_group',
|
|
87
|
+
entityType: 'STGP',
|
|
88
|
+
service: 'stageGroupService',
|
|
89
|
+
},
|
|
90
|
+
{ table: 'cr_wf_stage', entityType: 'STG', service: 'stageService' },
|
|
91
|
+
{ table: 'cr_wf_action', entityType: 'ACTN', service: 'actionService' },
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
// Fetch all base data
|
|
95
|
+
const getAllFactoryData = async (table: { table: string }) =>
|
|
96
|
+
this.dataSource.query(
|
|
97
|
+
`SELECT * FROM ${table.table} WHERE organization_id = -1 AND level_type = 'ORG' AND level_id = -1`,
|
|
98
|
+
);
|
|
99
|
+
const factoryData = await Promise.all(
|
|
100
|
+
workflowTables.map(getAllFactoryData),
|
|
101
|
+
);
|
|
102
|
+
const [workflows, stageGroups, stages, actions] = factoryData;
|
|
103
|
+
|
|
104
|
+
// === 1. Workflow mapping
|
|
105
|
+
const workflowIdMap: Record<number, number> = {};
|
|
106
|
+
for (const row of workflows) {
|
|
107
|
+
const { id, ...rest } = row;
|
|
108
|
+
const newWf = await this.workflowService.createEntity(
|
|
109
|
+
{
|
|
110
|
+
...rest,
|
|
111
|
+
organization_id,
|
|
112
|
+
level_id: organization_id,
|
|
113
|
+
entity_type: 'WRFW',
|
|
114
|
+
},
|
|
115
|
+
loggedInUser,
|
|
116
|
+
);
|
|
117
|
+
workflowIdMap[id] = newWf.id;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// === 2. StageGroup mapping (and save workflow ref from template data!)
|
|
121
|
+
const stageGroupIdMap: Record<number, number> = {};
|
|
122
|
+
// Include mapping from old stageGroupId to old workflowId to help with stage->workflow logic later:
|
|
123
|
+
const stageGroupToWorkflowMap: Record<number, number> = {};
|
|
124
|
+
for (const row of stageGroups) {
|
|
125
|
+
const { id, workflow_id, ...rest } = row;
|
|
126
|
+
const newSg = await this.stageGroupService.createEntity(
|
|
127
|
+
{
|
|
128
|
+
...rest,
|
|
129
|
+
workflow_id: workflowIdMap[workflow_id],
|
|
130
|
+
organization_id,
|
|
131
|
+
level_id: organization_id,
|
|
132
|
+
entity_type: 'STGP',
|
|
133
|
+
},
|
|
134
|
+
loggedInUser,
|
|
135
|
+
);
|
|
136
|
+
stageGroupIdMap[id] = newSg.id;
|
|
137
|
+
stageGroupToWorkflowMap[id] = workflow_id;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// === 3. Stage mapping — point to stageGroup and workflow
|
|
141
|
+
const stageIdMap: Record<number, number> = {};
|
|
142
|
+
const stageToStageGroupMap: Record<number, number> = {};
|
|
143
|
+
for (const row of stages) {
|
|
144
|
+
const { id, stage_group_id, ...rest } = row;
|
|
145
|
+
// Find the original parent workflow_id using the stageGroupToWorkflowMap
|
|
146
|
+
const originalWorkflowId = stageGroupToWorkflowMap[stage_group_id];
|
|
147
|
+
const newStage = await this.stageService.createEntity(
|
|
148
|
+
{
|
|
149
|
+
...rest,
|
|
150
|
+
stage_group_id: stageGroupIdMap[stage_group_id],
|
|
151
|
+
workflow_id: workflowIdMap[originalWorkflowId], // New workflow id!
|
|
152
|
+
organization_id,
|
|
153
|
+
level_id: organization_id,
|
|
154
|
+
entity_type: 'STG',
|
|
155
|
+
},
|
|
156
|
+
loggedInUser,
|
|
157
|
+
);
|
|
158
|
+
stageIdMap[id] = newStage.id;
|
|
159
|
+
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
|
+
|
|
166
|
+
const newStageId = stageIdMap[stage_id];
|
|
167
|
+
const oldStageGroupId = stageToStageGroupMap[stage_id];
|
|
168
|
+
const oldWorkflowId = stageGroupToWorkflowMap[oldStageGroupId];
|
|
169
|
+
const newWorkflowId = workflowIdMap[oldWorkflowId];
|
|
170
|
+
|
|
171
|
+
await this.actionService.createEntity(
|
|
172
|
+
{
|
|
173
|
+
...rest,
|
|
174
|
+
stage_id: newStageId,
|
|
175
|
+
workflow_id: newWorkflowId,
|
|
176
|
+
organization_id,
|
|
177
|
+
level_id: organization_id,
|
|
178
|
+
entity_type: 'ACTN',
|
|
179
|
+
},
|
|
180
|
+
loggedInUser,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
message: 'Workflow data populated successfully',
|
|
186
|
+
status: 'success',
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -12,8 +12,8 @@ export class WorkflowListMasterService extends EntityServiceImpl {
|
|
|
12
12
|
const results = await this.dataSource.query(
|
|
13
13
|
`
|
|
14
14
|
SELECT
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
ac.name AS name,
|
|
16
|
+
ac.logo AS logo,
|
|
17
17
|
ac.modalName AS modalName,
|
|
18
18
|
a.action_requirement AS actionRequirement
|
|
19
19
|
FROM cr_wf_stage_action_mapping sam
|
|
@@ -26,8 +26,8 @@ export class WorkflowListMasterService extends EntityServiceImpl {
|
|
|
26
26
|
|
|
27
27
|
// Add actionStatus and return formatted output
|
|
28
28
|
return results.map((item: any) => ({
|
|
29
|
-
logo: item.logo,
|
|
30
29
|
name: item.name,
|
|
30
|
+
logo: item.logo,
|
|
31
31
|
modalName: item.modalName,
|
|
32
32
|
actionRequirement: item.actionRequirement,
|
|
33
33
|
actionStatus: 'Done',
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
import { StageMovementData } from '../entity/stage-movement-data.entity';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class WorkflowMetaService {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository(StageMovementData)
|
|
10
|
+
private readonly stageMovementRepo: Repository<StageMovementData>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get the current active stage for a given mapped entity
|
|
15
|
+
*/
|
|
16
|
+
async getCurrentStage(
|
|
17
|
+
mapped_entity_type: string,
|
|
18
|
+
mapped_entity_id: number,
|
|
19
|
+
): Promise<StageMovementData | null> {
|
|
20
|
+
return this.stageMovementRepo.findOne({
|
|
21
|
+
where: {
|
|
22
|
+
mapped_entity_type,
|
|
23
|
+
mapped_entity_id,
|
|
24
|
+
is_current: 'Y',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get next stage ID based on current stage
|
|
31
|
+
* (Stub logic – replace with real stage transition resolution)
|
|
32
|
+
*/
|
|
33
|
+
async getNextStage(currentStage: StageMovementData): Promise<number | null> {
|
|
34
|
+
// TODO: Replace with actual logic based on mapping table
|
|
35
|
+
const nextStageId = currentStage.stage_action_mapping_id + 1;
|
|
36
|
+
const hasNext = true;
|
|
37
|
+
|
|
38
|
+
return hasNext ? nextStageId : null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Move mapped entity to the next stage in the workflow
|
|
43
|
+
*/
|
|
44
|
+
async moveToNextStage(
|
|
45
|
+
mapped_entity_type: string,
|
|
46
|
+
mapped_entity_id: number,
|
|
47
|
+
current_user_id: number,
|
|
48
|
+
): Promise<string> {
|
|
49
|
+
const now = new Date();
|
|
50
|
+
const currentStage = await this.getCurrentStage(mapped_entity_type, mapped_entity_id);
|
|
51
|
+
|
|
52
|
+
// Case 1: First stage – initialize
|
|
53
|
+
if (!currentStage) {
|
|
54
|
+
const firstStageId = 1; // TODO: Replace with actual logic to fetch first stage
|
|
55
|
+
|
|
56
|
+
await this.stageMovementRepo.save({
|
|
57
|
+
mapped_entity_type,
|
|
58
|
+
mapped_entity_id,
|
|
59
|
+
current_user_id,
|
|
60
|
+
stage_action_mapping_id: firstStageId,
|
|
61
|
+
start_date: now,
|
|
62
|
+
is_current: 'Y',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return 'Workflow started with the first stage.';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Case 2: Has next stage – move forward
|
|
69
|
+
const nextStageId = await this.getNextStage(currentStage);
|
|
70
|
+
|
|
71
|
+
if (nextStageId) {
|
|
72
|
+
// Close current stage
|
|
73
|
+
currentStage.end_date = now;
|
|
74
|
+
currentStage.is_current = 'N';
|
|
75
|
+
await this.stageMovementRepo.save(currentStage);
|
|
76
|
+
|
|
77
|
+
// Insert next stage
|
|
78
|
+
await this.stageMovementRepo.save({
|
|
79
|
+
entity_type: 'STAGE_MOVEMENT_DATA',
|
|
80
|
+
mapped_entity_type,
|
|
81
|
+
mapped_entity_id,
|
|
82
|
+
current_user_id,
|
|
83
|
+
stage_action_mapping_id: nextStageId,
|
|
84
|
+
start_date: now,
|
|
85
|
+
is_current: 'Y',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return `Moved to next stage (Stage ID: ${nextStageId}).`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Case 3: No next stage – mark workflow as done
|
|
92
|
+
currentStage.end_date = now;
|
|
93
|
+
currentStage.is_current = 'N';
|
|
94
|
+
await this.stageMovementRepo.save(currentStage);
|
|
95
|
+
|
|
96
|
+
return 'Workflow completed. No next stage available.';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,39 +1,44 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
|
-
import { Workflow } from './entity/workflow.entity';
|
|
3
|
-
import { WorkflowService } from './service/workflow.service';
|
|
4
|
-
import { StageGroup } from './entity/stage-group.entity';
|
|
5
|
-
import { Stage } from './entity/stage.entity';
|
|
6
|
-
import { ActionCategory } from './entity/action-category.entity';
|
|
7
|
-
import { CommTemplate } from './entity/comm-template.entity';
|
|
8
|
-
import { ActionTemplateMapping } from './entity/action-template-mapping.entity';
|
|
9
|
-
import { StageActionMapping } from './entity/stage-action-mapping.entity';
|
|
10
|
-
import { ActionCategoryService } from './service/action-category.service';
|
|
11
|
-
import { CommTemplateService } from './service/comm-template.service';
|
|
12
|
-
import { StageActionMappingService } from './service/stage-action-mapping.service';
|
|
13
|
-
import { ActionTemplateMappingService } from './service/action-template-mapping.service';
|
|
14
|
-
import { ActionService } from './service/action.service';
|
|
15
|
-
import { StageService } from './service/stage.service';
|
|
16
|
-
import { StageGroupService } from './service/stage-group.service';
|
|
17
2
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
+
import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
18
4
|
import { EntityModule } from '../meta/entity.module';
|
|
19
|
-
import { WorkflowListMasterService } from './service/workflow-list-master.service';
|
|
20
|
-
import { WorkflowListMasterController } from './controller/workflow-list-master.controller';
|
|
21
5
|
import { ActionTemplateMappingController } from './controller/action-template-mapping.controller';
|
|
22
|
-
import {
|
|
23
|
-
import { WorkflowRepository } from './repository/workflow.repository';
|
|
24
|
-
import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
6
|
+
import { ActionController } from './controller/action.controller';
|
|
25
7
|
import { CommTemplateController } from './controller/comm-template.controller';
|
|
26
|
-
import {
|
|
27
|
-
import { ActionEntity } from './entity/action.entity';
|
|
28
|
-
import { StageGroupRepository } from './repository/stage-group.repository';
|
|
8
|
+
import { EntityModificationController } from './controller/entity-modification.controller';
|
|
29
9
|
import { StageGroupController } from './controller/stage-group.controller';
|
|
30
10
|
import { StageController } from './controller/stage.controller';
|
|
11
|
+
import { WorkflowListMasterController } from './controller/workflow-list-master.controller';
|
|
12
|
+
import { WorkflowMetaController } from './controller/workflow-meta.controller';
|
|
13
|
+
import { WorkflowController } from './controller/workflow.controller';
|
|
14
|
+
import { ActionCategory } from './entity/action-category.entity';
|
|
15
|
+
import { ActionTemplateMapping } from './entity/action-template-mapping.entity';
|
|
16
|
+
import { ActionEntity } from './entity/action.entity';
|
|
17
|
+
import { CommTemplate } from './entity/comm-template.entity';
|
|
18
|
+
import { EntityModification } from './entity/entity-modification.entity';
|
|
19
|
+
import { StageActionMapping } from './entity/stage-action-mapping.entity';
|
|
20
|
+
import { StageGroup } from './entity/stage-group.entity';
|
|
21
|
+
import { StageMovementData } from './entity/stage-movement-data.entity';
|
|
22
|
+
import { Stage } from './entity/stage.entity';
|
|
23
|
+
import { TemplateAttach } from './entity/template-attach-mapper.entity';
|
|
24
|
+
import { Workflow } from './entity/workflow.entity';
|
|
25
|
+
import { CommTemplateRepository } from './repository/comm-template.repository';
|
|
26
|
+
import { StageGroupRepository } from './repository/stage-group.repository';
|
|
31
27
|
import { StageRepository } from './repository/stage.repository';
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
28
|
+
import { WorkflowRepository } from './repository/workflow.repository';
|
|
29
|
+
import { ActionCategoryService } from './service/action-category.service';
|
|
30
|
+
import { ActionTemplateMappingService } from './service/action-template-mapping.service';
|
|
31
|
+
import { ActionService } from './service/action.service';
|
|
32
|
+
import { CommTemplateService } from './service/comm-template.service';
|
|
34
33
|
import { EntityModificationService } from './service/entity-modification.service';
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
34
|
+
import { PopulateWorkflowService } from './service/populate-workflow.service';
|
|
35
|
+
import { StageActionMappingService } from './service/stage-action-mapping.service';
|
|
36
|
+
import { StageGroupService } from './service/stage-group.service';
|
|
37
|
+
import { StageService } from './service/stage.service';
|
|
38
|
+
import { WorkflowListMasterService } from './service/workflow-list-master.service';
|
|
39
|
+
import { WorkflowMetaService } from './service/workflow-meta.service';
|
|
40
|
+
import { WorkflowService } from './service/workflow.service';
|
|
41
|
+
import { ActionCategoryController } from './controller/action-category.controller';
|
|
37
42
|
|
|
38
43
|
@Module({
|
|
39
44
|
imports: [
|
|
@@ -46,7 +51,9 @@ import { EntityModificationController } from './controller/entity-modification.c
|
|
|
46
51
|
CommTemplate,
|
|
47
52
|
ActionTemplateMapping,
|
|
48
53
|
StageActionMapping,
|
|
54
|
+
StageMovementData,
|
|
49
55
|
EntityModification,
|
|
56
|
+
TemplateAttach,
|
|
50
57
|
]),
|
|
51
58
|
EntityModule,
|
|
52
59
|
ListMasterModule,
|
|
@@ -73,6 +80,9 @@ import { EntityModificationController } from './controller/entity-modification.c
|
|
|
73
80
|
CommTemplateRepository,
|
|
74
81
|
StageGroupRepository,
|
|
75
82
|
StageRepository,
|
|
83
|
+
WorkflowService,
|
|
84
|
+
WorkflowMetaService,
|
|
85
|
+
PopulateWorkflowService,
|
|
76
86
|
],
|
|
77
87
|
exports: [
|
|
78
88
|
'ActionCategoryService',
|
|
@@ -85,6 +95,8 @@ import { EntityModificationController } from './controller/entity-modification.c
|
|
|
85
95
|
WorkflowRepository,
|
|
86
96
|
StageGroupRepository,
|
|
87
97
|
StageRepository,
|
|
98
|
+
WorkflowMetaService,
|
|
99
|
+
PopulateWorkflowService,
|
|
88
100
|
],
|
|
89
101
|
controllers: [
|
|
90
102
|
WorkflowListMasterController,
|
|
@@ -94,7 +106,9 @@ import { EntityModificationController } from './controller/entity-modification.c
|
|
|
94
106
|
StageGroupController,
|
|
95
107
|
StageController,
|
|
96
108
|
ActionController,
|
|
109
|
+
WorkflowMetaController,
|
|
97
110
|
EntityModificationController,
|
|
111
|
+
ActionCategoryController,
|
|
98
112
|
],
|
|
99
113
|
})
|
|
100
114
|
export class WorkflowModule {}
|