rez_core 2.1.144 → 2.1.147
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/constant/global.constant.d.ts +1 -0
- package/dist/constant/global.constant.js +2 -1
- package/dist/constant/global.constant.js.map +1 -1
- package/dist/module/enterprise/repository/school.repository.js +18 -2
- package/dist/module/enterprise/repository/school.repository.js.map +1 -1
- 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 +3 -0
- package/dist/module/workflow/controller/action.controller.js +14 -0
- 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/entity-modification.controller.d.ts +8 -0
- package/dist/module/workflow/controller/entity-modification.controller.js +44 -0
- package/dist/module/workflow/controller/entity-modification.controller.js.map +1 -0
- 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 +1 -0
- package/dist/module/workflow/entity/action.entity.js +4 -0
- 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/entity-modification.entity.d.ts +13 -0
- package/dist/module/workflow/entity/entity-modification.entity.js +63 -0
- package/dist/module/workflow/entity/entity-modification.entity.js.map +1 -0
- 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 +20 -1
- package/dist/module/workflow/service/action-category.service.js.map +1 -1
- package/dist/module/workflow/service/action.service.d.ts +1 -0
- package/dist/module/workflow/service/action.service.js +72 -0
- 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/entity-modification.service.d.ts +8 -0
- package/dist/module/workflow/service/entity-modification.service.js +52 -0
- package/dist/module/workflow/service/entity-modification.service.js.map +1 -0
- 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 +48 -23
- package/dist/module/workflow/workflow.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/constant/global.constant.ts +2 -0
- package/src/module/enterprise/repository/school.repository.ts +23 -2
- 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 +11 -0
- package/src/module/workflow/controller/comm-template.controller.ts +5 -4
- package/src/module/workflow/controller/entity-modification.controller.ts +35 -0
- 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 -0
- package/src/module/workflow/entity/comm-template.entity.ts +18 -1
- package/src/module/workflow/entity/entity-modification.entity.ts +38 -0
- 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 +23 -1
- package/src/module/workflow/service/action-template-mapping.service.ts +1 -1
- package/src/module/workflow/service/action.service.ts +106 -0
- package/src/module/workflow/service/comm-template.service.ts +54 -1
- package/src/module/workflow/service/entity-modification.service.ts +67 -0
- 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 +48 -23
|
@@ -209,4 +209,110 @@ export class ActionService extends EntityServiceImpl {
|
|
|
209
209
|
value: row.name,
|
|
210
210
|
}));
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
async getActions(loggedInUser: UserData, stage_id: number) {
|
|
214
|
+
const { organization_id } = loggedInUser;
|
|
215
|
+
|
|
216
|
+
// Step 1: Get all action_ids for the provided stage_id
|
|
217
|
+
const stageActions = await this.dataSource.query(
|
|
218
|
+
`
|
|
219
|
+
SELECT id, action_id
|
|
220
|
+
FROM cr_wf_stage_action_mapping
|
|
221
|
+
WHERE stage_id = ?
|
|
222
|
+
`,
|
|
223
|
+
[stage_id],
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
if (!stageActions?.length) return [];
|
|
227
|
+
|
|
228
|
+
const actionIds = stageActions.map((sa) => sa.action_id);
|
|
229
|
+
const mappingIds = stageActions.map((sa) => sa.id);
|
|
230
|
+
|
|
231
|
+
const templateMappings = await this.dataSource.query(
|
|
232
|
+
`
|
|
233
|
+
SELECT template_code
|
|
234
|
+
FROM cr_wf_action_template_mapping
|
|
235
|
+
WHERE stg_act_mapping_id IN (?)
|
|
236
|
+
`,
|
|
237
|
+
[mappingIds],
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const templateCodes = templateMappings.map((tm) => tm.template_code);
|
|
241
|
+
|
|
242
|
+
// Step 3: Fetch template names from cr_wf_comm_template
|
|
243
|
+
let templateNameMap: Record<number, string> = {};
|
|
244
|
+
|
|
245
|
+
if (templateCodes.length > 0) {
|
|
246
|
+
const templates = await this.dataSource.query(
|
|
247
|
+
`
|
|
248
|
+
SELECT code, name
|
|
249
|
+
FROM cr_wf_comm_template
|
|
250
|
+
WHERE code IN (?)
|
|
251
|
+
AND organization_id = ?
|
|
252
|
+
`,
|
|
253
|
+
[templateCodes, organization_id],
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// Map template_code to name
|
|
257
|
+
const codeToNameMap = templates.reduce((acc, curr) => {
|
|
258
|
+
acc[curr.code] = curr.name;
|
|
259
|
+
return acc;
|
|
260
|
+
}, {});
|
|
261
|
+
|
|
262
|
+
// Group template names by mapping_id
|
|
263
|
+
templateMappings.forEach((tm) => {
|
|
264
|
+
const mappingId = tm.stg_act_mapping_id;
|
|
265
|
+
const name = codeToNameMap[tm.template_code];
|
|
266
|
+
if (name) {
|
|
267
|
+
if (!templateNameMap[mappingId]) {
|
|
268
|
+
templateNameMap[mappingId] = name;
|
|
269
|
+
} else {
|
|
270
|
+
templateNameMap[mappingId] += `, ${name}`;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Step 2: Fetch action details based on those action_ids
|
|
277
|
+
// Step 4: Fetch action details
|
|
278
|
+
const result = await this.dataSource.query(
|
|
279
|
+
`
|
|
280
|
+
SELECT
|
|
281
|
+
a.id,
|
|
282
|
+
a.name AS action_name,
|
|
283
|
+
ac.name AS action_category,
|
|
284
|
+
ar.name AS action_requirement
|
|
285
|
+
FROM cr_wf_action a
|
|
286
|
+
LEFT JOIN cr_wf_action_category ac
|
|
287
|
+
ON ac.id = a.action_cat_id
|
|
288
|
+
LEFT JOIN cr_list_master_items ar
|
|
289
|
+
ON ar.id = a.action_requirement
|
|
290
|
+
AND ar.listtype = 'ACRQ'
|
|
291
|
+
AND ar.organization_id = ?
|
|
292
|
+
WHERE a.organization_id = ?
|
|
293
|
+
AND a.id IN (?)
|
|
294
|
+
`,
|
|
295
|
+
[organization_id, organization_id, actionIds],
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// Step 5: Attach templates (comma-separated) to each result row
|
|
299
|
+
const enrichedResult = result.map((row) => {
|
|
300
|
+
// Find all mapping_ids where action_id == current row.id
|
|
301
|
+
const relatedMappingIds = stageActions
|
|
302
|
+
.filter((sa) => sa.action_id === row.id)
|
|
303
|
+
.map((sa) => sa.id);
|
|
304
|
+
|
|
305
|
+
// Collect all template names across those mapping ids
|
|
306
|
+
const allNames = relatedMappingIds
|
|
307
|
+
.map((mid) => templateNameMap[mid])
|
|
308
|
+
.filter(Boolean);
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
...row,
|
|
312
|
+
template: allNames.length ? allNames.join(', ') : '',
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
return enrichedResult;
|
|
317
|
+
}
|
|
212
318
|
}
|
|
@@ -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,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BadRequestException,
|
|
3
|
+
Injectable,
|
|
4
|
+
NotFoundException,
|
|
5
|
+
} from '@nestjs/common';
|
|
6
|
+
import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
|
|
7
|
+
import { UserData } from 'src/module/user/entity/user.entity';
|
|
8
|
+
import { DataSource } from 'typeorm';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class EntityModificationService extends EntityServiceImpl {
|
|
12
|
+
constructor(private readonly dataSource: DataSource) {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
async logModification(modificationData: any, loggedInUser: UserData) {
|
|
16
|
+
const { mapped_entity_type, mapped_entity_id, attribute_key } =
|
|
17
|
+
modificationData;
|
|
18
|
+
const { organization_id } = loggedInUser;
|
|
19
|
+
|
|
20
|
+
if (!mapped_entity_type || !mapped_entity_id || !attribute_key) {
|
|
21
|
+
throw new BadRequestException(
|
|
22
|
+
'Missing required modification data: mapped_entity_type, mapped_entity_id, or attribute_key',
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Step 1: Fetch db_table_name from cr_entity_master
|
|
27
|
+
const [entityMeta] = await this.dataSource.query(
|
|
28
|
+
`
|
|
29
|
+
SELECT db_table_name
|
|
30
|
+
FROM cr_entity_master
|
|
31
|
+
WHERE mapped_entity_type = ? AND organization_id = ?
|
|
32
|
+
`,
|
|
33
|
+
[mapped_entity_type, organization_id],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!entityMeta || !entityMeta.db_table_name) {
|
|
37
|
+
throw new NotFoundException(
|
|
38
|
+
'Entity metadata not found in cr_entity_master',
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const tableName = entityMeta.db_table_name;
|
|
43
|
+
|
|
44
|
+
// Step 2: Get the row from the target table using mapped_entity_id
|
|
45
|
+
const [entityRow] = await this.dataSource.query(
|
|
46
|
+
`
|
|
47
|
+
SELECT * FROM ${tableName} WHERE id = ?
|
|
48
|
+
`,
|
|
49
|
+
[mapped_entity_id],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!entityRow) {
|
|
53
|
+
throw new NotFoundException(
|
|
54
|
+
`No record found in ${tableName} with ID ${mapped_entity_id}`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Step 3: Extract current value from the target column
|
|
59
|
+
const currentAttributeValue = entityRow[attribute_key];
|
|
60
|
+
|
|
61
|
+
// Step 4: Set current_value in modificationData
|
|
62
|
+
modificationData.current_value = currentAttributeValue;
|
|
63
|
+
|
|
64
|
+
// Step 5: Call super.createEntity with updated modificationData
|
|
65
|
+
return await super.createEntity(modificationData, loggedInUser);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -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,35 +1,44 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
+
import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
4
|
+
import { EntityModule } from '../meta/entity.module';
|
|
5
|
+
import { ActionTemplateMappingController } from './controller/action-template-mapping.controller';
|
|
6
|
+
import { ActionController } from './controller/action.controller';
|
|
7
|
+
import { CommTemplateController } from './controller/comm-template.controller';
|
|
8
|
+
import { EntityModificationController } from './controller/entity-modification.controller';
|
|
9
|
+
import { StageGroupController } from './controller/stage-group.controller';
|
|
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';
|
|
6
14
|
import { ActionCategory } from './entity/action-category.entity';
|
|
7
|
-
import { CommTemplate } from './entity/comm-template.entity';
|
|
8
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';
|
|
9
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';
|
|
27
|
+
import { StageRepository } from './repository/stage.repository';
|
|
28
|
+
import { WorkflowRepository } from './repository/workflow.repository';
|
|
10
29
|
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
30
|
import { ActionTemplateMappingService } from './service/action-template-mapping.service';
|
|
14
31
|
import { ActionService } from './service/action.service';
|
|
15
|
-
import {
|
|
32
|
+
import { CommTemplateService } from './service/comm-template.service';
|
|
33
|
+
import { EntityModificationService } from './service/entity-modification.service';
|
|
34
|
+
import { PopulateWorkflowService } from './service/populate-workflow.service';
|
|
35
|
+
import { StageActionMappingService } from './service/stage-action-mapping.service';
|
|
16
36
|
import { StageGroupService } from './service/stage-group.service';
|
|
17
|
-
import {
|
|
18
|
-
import { EntityModule } from '../meta/entity.module';
|
|
37
|
+
import { StageService } from './service/stage.service';
|
|
19
38
|
import { WorkflowListMasterService } from './service/workflow-list-master.service';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { WorkflowRepository } from './repository/workflow.repository';
|
|
24
|
-
import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
25
|
-
import { CommTemplateController } from './controller/comm-template.controller';
|
|
26
|
-
import { CommTemplateRepository } from './repository/comm-template.repository';
|
|
27
|
-
import { ActionEntity } from './entity/action.entity';
|
|
28
|
-
import { StageGroupRepository } from './repository/stage-group.repository';
|
|
29
|
-
import { StageGroupController } from './controller/stage-group.controller';
|
|
30
|
-
import { StageController } from './controller/stage.controller';
|
|
31
|
-
import { StageRepository } from './repository/stage.repository';
|
|
32
|
-
import { ActionController } from './controller/action.controller';
|
|
39
|
+
import { WorkflowMetaService } from './service/workflow-meta.service';
|
|
40
|
+
import { WorkflowService } from './service/workflow.service';
|
|
41
|
+
import { ActionCategoryController } from './controller/action-category.controller';
|
|
33
42
|
|
|
34
43
|
@Module({
|
|
35
44
|
imports: [
|
|
@@ -42,6 +51,9 @@ import { ActionController } from './controller/action.controller';
|
|
|
42
51
|
CommTemplate,
|
|
43
52
|
ActionTemplateMapping,
|
|
44
53
|
StageActionMapping,
|
|
54
|
+
StageMovementData,
|
|
55
|
+
EntityModification,
|
|
56
|
+
TemplateAttach,
|
|
45
57
|
]),
|
|
46
58
|
EntityModule,
|
|
47
59
|
ListMasterModule,
|
|
@@ -57,6 +69,10 @@ import { ActionController } from './controller/action.controller';
|
|
|
57
69
|
{ provide: 'StageService', useClass: StageService },
|
|
58
70
|
{ provide: 'StageGroupService', useClass: StageGroupService },
|
|
59
71
|
{ provide: 'WorkflowService', useClass: WorkflowService },
|
|
72
|
+
{
|
|
73
|
+
provide: 'EntityModificationService',
|
|
74
|
+
useClass: EntityModificationService,
|
|
75
|
+
},
|
|
60
76
|
WorkflowListMasterService,
|
|
61
77
|
ActionTemplateMappingService,
|
|
62
78
|
WorkflowRepository,
|
|
@@ -64,6 +80,9 @@ import { ActionController } from './controller/action.controller';
|
|
|
64
80
|
CommTemplateRepository,
|
|
65
81
|
StageGroupRepository,
|
|
66
82
|
StageRepository,
|
|
83
|
+
WorkflowService,
|
|
84
|
+
WorkflowMetaService,
|
|
85
|
+
PopulateWorkflowService,
|
|
67
86
|
],
|
|
68
87
|
exports: [
|
|
69
88
|
'ActionCategoryService',
|
|
@@ -72,9 +91,12 @@ import { ActionController } from './controller/action.controller';
|
|
|
72
91
|
'ActionService',
|
|
73
92
|
'StageService',
|
|
74
93
|
'StageGroupService',
|
|
94
|
+
'EntityModificationService',
|
|
75
95
|
WorkflowRepository,
|
|
76
96
|
StageGroupRepository,
|
|
77
97
|
StageRepository,
|
|
98
|
+
WorkflowMetaService,
|
|
99
|
+
PopulateWorkflowService,
|
|
78
100
|
],
|
|
79
101
|
controllers: [
|
|
80
102
|
WorkflowListMasterController,
|
|
@@ -84,6 +106,9 @@ import { ActionController } from './controller/action.controller';
|
|
|
84
106
|
StageGroupController,
|
|
85
107
|
StageController,
|
|
86
108
|
ActionController,
|
|
109
|
+
WorkflowMetaController,
|
|
110
|
+
EntityModificationController,
|
|
111
|
+
ActionCategoryController,
|
|
87
112
|
],
|
|
88
113
|
})
|
|
89
114
|
export class WorkflowModule {}
|