rez_core 5.0.89 → 5.0.90

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.
Files changed (82) hide show
  1. package/dist/module/meta/service/entity-relation.service.d.ts +1 -3
  2. package/dist/module/meta/service/entity-relation.service.js +22 -31
  3. package/dist/module/meta/service/entity-relation.service.js.map +1 -1
  4. package/dist/module/module/service/module-access.service.d.ts +3 -1
  5. package/dist/module/module/service/module-access.service.js +11 -4
  6. package/dist/module/module/service/module-access.service.js.map +1 -1
  7. package/dist/module/notification/controller/notification.controller.d.ts +1 -1
  8. package/dist/module/notification/service/notification.service.d.ts +6 -4
  9. package/dist/module/notification/service/notification.service.js +22 -20
  10. package/dist/module/notification/service/notification.service.js.map +1 -1
  11. package/dist/module/workflow/controller/action.controller.d.ts +5 -2
  12. package/dist/module/workflow/controller/form-master.controller.d.ts +4 -1
  13. package/dist/module/workflow/repository/action-data.repository.d.ts +2 -3
  14. package/dist/module/workflow/repository/action-data.repository.js +29 -18
  15. package/dist/module/workflow/repository/action-data.repository.js.map +1 -1
  16. package/dist/module/workflow/repository/action.repository.d.ts +6 -7
  17. package/dist/module/workflow/repository/action.repository.js +53 -61
  18. package/dist/module/workflow/repository/action.repository.js.map +1 -1
  19. package/dist/module/workflow/repository/comm-template.repository.d.ts +2 -3
  20. package/dist/module/workflow/repository/comm-template.repository.js +15 -9
  21. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  22. package/dist/module/workflow/repository/form-master.repository.d.ts +7 -4
  23. package/dist/module/workflow/repository/form-master.repository.js +14 -11
  24. package/dist/module/workflow/repository/form-master.repository.js.map +1 -1
  25. package/dist/module/workflow/repository/stage-group.repository.d.ts +4 -5
  26. package/dist/module/workflow/repository/stage-group.repository.js +34 -35
  27. package/dist/module/workflow/repository/stage-group.repository.js.map +1 -1
  28. package/dist/module/workflow/repository/stage-movement.repository.d.ts +6 -3
  29. package/dist/module/workflow/repository/stage-movement.repository.js +30 -17
  30. package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -1
  31. package/dist/module/workflow/service/action.service.d.ts +13 -5
  32. package/dist/module/workflow/service/action.service.js +71 -20
  33. package/dist/module/workflow/service/action.service.js.map +1 -1
  34. package/dist/module/workflow/service/entity-modification.service.d.ts +3 -3
  35. package/dist/module/workflow/service/entity-modification.service.js +4 -4
  36. package/dist/module/workflow/service/entity-modification.service.js.map +1 -1
  37. package/dist/module/workflow/service/form-master.service.d.ts +4 -1
  38. package/dist/module/workflow/service/stage-group.service.d.ts +2 -7
  39. package/dist/module/workflow/service/stage-group.service.js +19 -17
  40. package/dist/module/workflow/service/stage-group.service.js.map +1 -1
  41. package/dist/module/workflow/service/stage.service.d.ts +2 -3
  42. package/dist/module/workflow/service/stage.service.js +24 -11
  43. package/dist/module/workflow/service/stage.service.js.map +1 -1
  44. package/dist/module/workflow/service/task.service.d.ts +2 -5
  45. package/dist/module/workflow/service/task.service.js +44 -45
  46. package/dist/module/workflow/service/task.service.js.map +1 -1
  47. package/dist/module/workflow/service/workflow-list-master.service.d.ts +1 -3
  48. package/dist/module/workflow/service/workflow-list-master.service.js +38 -26
  49. package/dist/module/workflow/service/workflow-list-master.service.js.map +1 -1
  50. package/dist/module/workflow/service/workflow-meta.service.d.ts +6 -3
  51. package/dist/module/workflow/service/workflow-meta.service.js +78 -50
  52. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  53. package/dist/module/workflow/service/workflow.service.d.ts +1 -3
  54. package/dist/module/workflow/service/workflow.service.js +10 -6
  55. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  56. package/dist/module/workflow-schedule/processors/schedule.processor.d.ts +4 -2
  57. package/dist/module/workflow-schedule/processors/schedule.processor.js +51 -38
  58. package/dist/module/workflow-schedule/processors/schedule.processor.js.map +1 -1
  59. package/dist/module/workflow-schedule/service/workflow-schedule.service.d.ts +2 -3
  60. package/dist/module/workflow-schedule/service/workflow-schedule.service.js +15 -14
  61. package/dist/module/workflow-schedule/service/workflow-schedule.service.js.map +1 -1
  62. package/dist/tsconfig.build.tsbuildinfo +1 -1
  63. package/package.json +1 -1
  64. package/src/module/meta/service/entity-relation.service.ts +23 -41
  65. package/src/module/module/service/module-access.service.ts +8 -4
  66. package/src/module/notification/service/notification.service.ts +24 -20
  67. package/src/module/workflow/repository/action-data.repository.ts +33 -28
  68. package/src/module/workflow/repository/action.repository.ts +74 -77
  69. package/src/module/workflow/repository/comm-template.repository.ts +19 -13
  70. package/src/module/workflow/repository/form-master.repository.ts +15 -24
  71. package/src/module/workflow/repository/stage-group.repository.ts +41 -52
  72. package/src/module/workflow/repository/stage-movement.repository.ts +35 -32
  73. package/src/module/workflow/service/action.service.ts +70 -43
  74. package/src/module/workflow/service/entity-modification.service.ts +3 -3
  75. package/src/module/workflow/service/stage-group.service.ts +21 -19
  76. package/src/module/workflow/service/stage.service.ts +36 -28
  77. package/src/module/workflow/service/task.service.ts +53 -56
  78. package/src/module/workflow/service/workflow-list-master.service.ts +42 -34
  79. package/src/module/workflow/service/workflow-meta.service.ts +81 -77
  80. package/src/module/workflow/service/workflow.service.ts +9 -5
  81. package/src/module/workflow-schedule/processors/schedule.processor.ts +133 -97
  82. package/src/module/workflow-schedule/service/workflow-schedule.service.ts +24 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "5.0.89",
3
+ "version": "5.0.90",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -5,8 +5,7 @@ import { EntityMasterRepository } from '../repository/entity-master.repository';
5
5
 
6
6
  @Injectable()
7
7
  export class EntityRelationService extends EntityServiceImpl {
8
- constructor(private readonly dataSource: DataSource,
9
- private entityMasterRepo: EntityMasterRepository) {
8
+ constructor(private entityMasterRepo: EntityMasterRepository) {
10
9
  super();
11
10
  }
12
11
 
@@ -15,12 +14,18 @@ export class EntityRelationService extends EntityServiceImpl {
15
14
  loggedInUser: any,
16
15
  includeSelf = false,
17
16
  ): Promise<any> {
18
- const relations = await this.dataSource.query(
19
- `SELECT name as label, target_entity_type as value, id
20
- FROM frm_entity_relation
21
- WHERE source_entity_type = $1 AND organization_id = $2`,
22
- [entityType, loggedInUser.organization_id],
23
- );
17
+ const entityRelationRepo = this.reflectionHelper.getRepoService('EntityRelation');
18
+
19
+ const relations = await entityRelationRepo
20
+ .createQueryBuilder("er")
21
+ .select([
22
+ "er.name AS label",
23
+ "er.target_entity_type AS value",
24
+ "er.id AS id",
25
+ ])
26
+ .where("er.source_entity_type = :entityType", { entityType })
27
+ .andWhere("er.organization_id = :orgId", { orgId: loggedInUser.organization_id })
28
+ .getRawMany();
24
29
 
25
30
  if (includeSelf) {
26
31
  const entity = await this.entityMasterRepo.getEntityByMappedEntityType(entityType, loggedInUser.organization_id);
@@ -46,40 +51,17 @@ export class EntityRelationService extends EntityServiceImpl {
46
51
 
47
52
  if (!targetIds.length) return [];
48
53
 
49
- let paramIndex = 1;
50
- const params: any[] = [];
51
-
52
- // $1 and $2 are text (entity types)
53
- params.push(sourceEntity); // do NOT convert to string, pg will treat as text
54
- const sourceEntityParam = `$${paramIndex++}`;
55
-
56
- params.push(targetEntity);
57
- const targetEntityParam = `$${paramIndex++}`;
58
-
59
- // Build placeholders for IDs → IDs must remain NUMBER
60
- const idPlaceholders = targetIds
61
- .map((id) => {
62
- params.push(Number(id)); // ✔ FIX: Use Number
63
- return `$${paramIndex++}`;
64
- })
65
- .join(", ");
66
-
67
- // org id
68
- params.push(Number(orgId)); // ✔ FIX: Use Number
69
- const orgPlaceholder = `$${paramIndex}`;
70
-
71
- const sql = `
72
- SELECT DISTINCT source_entity_id
73
- FROM frm_entity_relation_data
74
- WHERE source_entity_type = ${sourceEntityParam}
75
- AND target_entity_type = ${targetEntityParam}
76
- AND target_entity_id IN (${idPlaceholders})
77
- AND organization_id = ${orgPlaceholder}
78
- `;
79
-
80
- const rows = await this.dataSource.query(sql, params);
54
+ const entityRelationRepo = this.reflectionHelper.getRepoService('EntityRelation');
55
+ const rows = await entityRelationRepo
56
+ .createQueryBuilder("erd")
57
+ .select("DISTINCT erd.source_entity_id", "source_entity_id")
58
+ .where("erd.source_entity_type = :sourceEntity", { sourceEntity })
59
+ .andWhere("erd.target_entity_type = :targetEntity", { targetEntity })
60
+ .andWhere("erd.target_entity_id IN (:...targetIds)", { targetIds })
61
+ .andWhere("erd.organization_id = :orgId", { orgId })
62
+ .getRawMany();
81
63
 
82
- return rows.map((r: any) => Number(r.source_entity_id));
64
+ return rows.map((r) => Number(r.source_entity_id));
83
65
  }
84
66
 
85
67
 
@@ -11,6 +11,7 @@ import { DataSource, EntityManager } from 'typeorm';
11
11
  import { UserData } from 'src/module/user/entity/user.entity';
12
12
  import { MenuRepository } from '../repository/menu.repository';
13
13
  import { ListMasterService } from 'src/module/listmaster/service/list-master.service';
14
+ import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
14
15
 
15
16
  @Injectable()
16
17
  export class ModuleAccessService {
@@ -20,6 +21,7 @@ export class ModuleAccessService {
20
21
  private readonly dataSource: DataSource,
21
22
  @Inject('ListMasterService')
22
23
  private readonly listMasterService: ListMasterService,
24
+ private readonly reflectionHelper: ReflectionHelper
23
25
  ) {}
24
26
 
25
27
  async getModules({ appcode,loggedInUser }: { appcode: string ,loggedInUser: UserData}) {
@@ -172,11 +174,13 @@ export class ModuleAccessService {
172
174
 
173
175
  // Step 3: If level_type is SCH, check school status using raw query
174
176
  if (level_type === 'SCH') {
175
- const result = await this.dataSource.query(
176
- `SELECT * FROM sso_school WHERE id = ${level_id}`
177
- );
177
+ const schoolRepo = this.reflectionHelper.getRepoService('SSOSchool');
178
178
 
179
- const school = result?.[0];
179
+ const school = await schoolRepo.findOne({
180
+ where: {
181
+ id: level_id
182
+ }
183
+ });
180
184
 
181
185
  const resolveStatus = await this.listMasterService.getResolvedListCode(
182
186
  STATUS_INACTIVE,
@@ -1,16 +1,18 @@
1
1
  import { Inject, Injectable } from '@nestjs/common';
2
- import { DataSource } from 'typeorm';
2
+ import { DataSource, EntityManager } from 'typeorm';
3
3
  import { MediaDataService } from 'src/module/meta/service/media-data.service';
4
4
  import * as admin from 'firebase-admin';
5
5
  import axios from 'axios';
6
6
  import { ConfigService } from '@nestjs/config';
7
+ import { ReflectionHelper } from 'src/utils/service/reflection-helper.service';
7
8
 
8
9
  @Injectable()
9
10
  export class NotificationsService {
10
11
  constructor(
11
- private readonly dataSource: DataSource,
12
+ private readonly entityManager: EntityManager,
12
13
  private readonly mediaDataService: MediaDataService,
13
14
  private readonly configService: ConfigService,
15
+ private readonly reflectionHelper: ReflectionHelper,
14
16
  @Inject('FIREBASE_ADMIN') private readonly firebaseAdmin: typeof admin,
15
17
  ) {}
16
18
 
@@ -90,11 +92,7 @@ export class NotificationsService {
90
92
  AND n.level_type = $${paramIndex + 2}
91
93
  `;
92
94
 
93
- const params: string[] = [
94
- String(id),
95
- String(level_id),
96
- String(level_type),
97
- ];
95
+ const params: string[] = [String(id), String(level_id), String(level_type)];
98
96
  paramIndex += 3;
99
97
 
100
98
  //
@@ -111,7 +109,7 @@ export class NotificationsService {
111
109
  //
112
110
  // Execute query
113
111
  //
114
- const notifications = await this.dataSource.query(sql, params);
112
+ const notifications = await this.entityManager.query(sql, params);
115
113
 
116
114
  //
117
115
  // Enrich profile image + user name
@@ -119,7 +117,8 @@ export class NotificationsService {
119
117
  const mediaCache = new Map();
120
118
 
121
119
  for (const notification of notifications) {
122
- notification.is_read = notification.is_read === 1 || notification.is_read === '1';
120
+ notification.is_read =
121
+ notification.is_read === 1 || notification.is_read === '1';
123
122
 
124
123
  try {
125
124
  const baseUrl = this.configService.get<string>('REDIRECT_BE_URL');
@@ -145,16 +144,21 @@ export class NotificationsService {
145
144
  async markAllAsRead(loggedInUser: any) {
146
145
  const { id, level_id, level_type } = loggedInUser;
147
146
 
148
- const query = `
149
- UPDATE frm_notification
150
- SET is_read = 1
151
- WHERE user_id = $1 AND level_id = $2 AND level_type = $3 AND is_read = 0
152
- `;
153
-
154
- const params = [id, level_id, level_type];
155
-
156
- const result = await this.dataSource.query(query, params);
157
-
158
- return { success: true, affectedRows: result.affectedRows || 0 };
147
+ const notificationRepo =
148
+ this.reflectionHelper.getRepoService('NotificationData');
149
+
150
+ const result = await notificationRepo.update(
151
+ {
152
+ user_id: id,
153
+ level_id: level_id,
154
+ level_type: level_type,
155
+ is_read: 0,
156
+ },
157
+ {
158
+ is_read: 1,
159
+ },
160
+ );
161
+
162
+ return { success: true, affectedRows: result.affected || 0 };
159
163
  }
160
164
  }
@@ -1,23 +1,22 @@
1
1
  import { BadRequestException, Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { ActionDataEntity } from '../entity/action-data.entity';
4
- import { DataSource, LessThan, Repository } from 'typeorm';
4
+ import { LessThan, Repository } from 'typeorm';
5
5
  import { UserData } from 'src/module/user/entity/user.entity';
6
6
  import { TaskDataEntity } from '../entity/task-data.entity';
7
7
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
8
8
  import { FORM_STATUS_TO_BE_SENT } from 'src/constant/global.constant';
9
9
  import { ConfigService } from '@nestjs/config';
10
10
  import axios from 'axios';
11
- import { WorkflowAutomationEngineService } from 'src/module/workflow-automation/service/workflow-automation-engine.service';
11
+ import {
12
+ WorkflowAutomationEngineService,
13
+ } from 'src/module/workflow-automation/service/workflow-automation-engine.service';
12
14
 
13
15
  @Injectable()
14
16
  export class ActionDataRepository extends EntityServiceImpl {
15
17
  constructor(
16
18
  @InjectRepository(ActionDataEntity)
17
19
  private readonly actionDataRepo: Repository<ActionDataEntity>,
18
- private readonly dataSource: DataSource,
19
- // @InjectRepository(FormDataEntity)
20
- // private readonly formRepo: Repository<FormDataEntity>,
21
20
  @InjectRepository(TaskDataEntity)
22
21
  private readonly TaskRepository: Repository<TaskDataEntity>,
23
22
  private readonly configService: ConfigService,
@@ -39,10 +38,14 @@ export class ActionDataRepository extends EntityServiceImpl {
39
38
 
40
39
  if (action.length > 0) {
41
40
  for (const act of action) {
42
- const is_mandatory = await this.dataSource.query(
43
- `SELECT code FROM frm_list_master_items WHERE id = $1 and organization_id = $2 LIMIT 1;`,
44
- [act.action_requirement, loggedInUser.organization_id],
45
- );
41
+ const listMasterItemsRepo = this.reflectionHelper.getRepoService('ListMasterItems');
42
+ const is_mandatory = await listMasterItemsRepo.findOne({
43
+ where: {
44
+ id: act.action_requirement,
45
+ organization_id: loggedInUser.organization_id,
46
+ },
47
+ });
48
+
46
49
  const isFirst = act.sequence == minSequence;
47
50
  const actionData = this.actionDataRepo.create({
48
51
  stage_id: act.stage_id,
@@ -55,7 +58,7 @@ export class ActionDataRepository extends EntityServiceImpl {
55
58
  mapped_entity_type,
56
59
  is_current: isFirst ? 'Y' : null,
57
60
  start_time: isFirst ? new Date() : null,
58
- is_mandatory: is_mandatory[0]?.code === 'mandatory' ? true : false,
61
+ is_mandatory: is_mandatory?.code === 'mandatory' ? true : false,
59
62
  category: act?.action_category_code,
60
63
  } as ActionDataEntity);
61
64
  await this.actionDataRepo.save(actionData);
@@ -91,7 +94,7 @@ export class ActionDataRepository extends EntityServiceImpl {
91
94
  status: FORM_STATUS_TO_BE_SENT,
92
95
  action_id: act.id,
93
96
  created_date: istDate,
94
- pdf_template: act.pdf_template
97
+ pdf_template: act.pdf_template,
95
98
  };
96
99
 
97
100
  const createdEntity = await super.createEntity(
@@ -100,23 +103,25 @@ export class ActionDataRepository extends EntityServiceImpl {
100
103
  );
101
104
  // THEN INSERT SDFM IN RELATION TASK TABLE
102
105
 
103
- let relationData = await this.dataSource.query(
104
- `SELECT * FROM frm_entity_relation WHERE source_entity_type = $1 AND target_entity_type = $2`,
105
- [createdEntity.mapped_entity_type, createdEntity.entity_type],
106
- );
106
+ const entityRelationRepo = this.reflectionHelper.getRepoService('EntityRelation');
107
+ let relationData = await entityRelationRepo.findOne({
108
+ where: {
109
+ source_entity_type: createdEntity.mapped_entity_type,
110
+ target_entity_type: createdEntity.entity_type,
111
+ },
112
+ });
107
113
 
108
114
  if (relationData) {
109
- await this.dataSource.query(
110
- `INSERT INTO frm_entity_relation_data (organization_id, source_entity_id, source_entity_type, target_entity_id, target_entity_type, relation_type) VALUES ($1, $2, $3, $4, $5,$6)`,
111
- [
112
- loggedInUser.organization_id,
113
- createdEntity.mapped_entity_id,
114
- createdEntity.mapped_entity_type,
115
- createdEntity.id,
116
- createdEntity.entity_type,
117
- relationData[0]?.relation_type,
118
- ],
119
- );
115
+ const entityRelationDataRepo = this.reflectionHelper.getRepoService('EntityRelationData');
116
+
117
+ await entityRelationDataRepo.save({
118
+ organization_id: loggedInUser.organization_id,
119
+ source_entity_id: createdEntity.mapped_entity_id,
120
+ source_entity_type: createdEntity.mapped_entity_type,
121
+ target_entity_id: createdEntity.id,
122
+ target_entity_type: createdEntity.entity_type,
123
+ relation_type: relationData?.relation_type,
124
+ });
120
125
  }
121
126
 
122
127
  await this.workflowAutomationEngineService.handleEntityEvent(
@@ -261,8 +266,8 @@ export class ActionDataRepository extends EntityServiceImpl {
261
266
  where: {
262
267
  code: 'in_progress',
263
268
  organization_id: organization_id,
264
- listtype: 'TKST'
265
- }
269
+ listtype: 'TKST',
270
+ },
266
271
  });
267
272
 
268
273
  task.status = listMasterItem.id ?? task.status;
@@ -1,36 +1,22 @@
1
- import {
2
- BadRequestException,
3
- Inject,
4
- Injectable,
5
- NotFoundException,
6
- } from '@nestjs/common';
7
- import { InjectRepository } from '@nestjs/typeorm';
8
- import { DataSource, In, Repository } from 'typeorm';
9
- import { ActionEntity } from '../entity/action.entity';
1
+ import { BadRequestException, Injectable } from '@nestjs/common';
2
+ import { In } from 'typeorm';
10
3
  import { UserData } from 'src/module/user/entity/user.entity';
11
4
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
12
5
 
13
6
  @Injectable()
14
7
  export class ActionRepository {
15
- constructor(
16
- @InjectRepository(ActionEntity)
17
- private readonly actionRepository: Repository<ActionEntity>,
18
- private readonly dataSource: DataSource,
19
- private readonly reflectionHelper: ReflectionHelper,
20
- ) {
21
- }
8
+ constructor(private readonly reflectionHelper: ReflectionHelper) {}
22
9
 
23
10
  async getReasonCode(loggedInUser: UserData): Promise<any> {
24
11
  const { organization_id } = loggedInUser;
25
- const result = await this.dataSource.query(
26
- `
27
- SELECT name, type
28
- FROM frm_list_master
29
- WHERE organization_id = $1
30
- AND source = 'master'
31
- `,
32
- [organization_id],
33
- );
12
+ const listMasterItemsRepo =
13
+ this.reflectionHelper.getRepoService('ListMasterItems');
14
+ const result = await listMasterItemsRepo.find({
15
+ where: {
16
+ organization_id,
17
+ source: 'master',
18
+ },
19
+ });
34
20
 
35
21
  const formatted = result.map((item: any) => ({
36
22
  label: item.name,
@@ -45,15 +31,16 @@ export class ActionRepository {
45
31
  if (!list_type) {
46
32
  throw new BadRequestException('list_type is required');
47
33
  }
48
- const result = await this.dataSource.query(
49
- `
50
- SELECT name, id
51
- FROM frm_list_master_items
52
- WHERE listtype = $1
53
- AND organization_id = $2
54
- `,
55
- [list_type, organization_id],
56
- );
34
+
35
+ const listMasterItemsRepo =
36
+ this.reflectionHelper.getRepoService('ListMasterItems');
37
+
38
+ const result = await listMasterItemsRepo.find({
39
+ where: {
40
+ listtype: list_type,
41
+ organization_id,
42
+ },
43
+ });
57
44
 
58
45
  // Format as array of key-value pairs
59
46
  return result.map((row: any) => ({
@@ -65,7 +52,8 @@ export class ActionRepository {
65
52
  async getActions(loggedInUser: UserData, stage_id: number) {
66
53
  const { organization_id } = loggedInUser;
67
54
 
68
- const workflowStageActionRepo = this.reflectionHelper.getRepoService('StageActionMapping');
55
+ const workflowStageActionRepo =
56
+ this.reflectionHelper.getRepoService('StageActionMapping');
69
57
 
70
58
  // Step 1: Get all action_ids for the provided stage_id
71
59
  const stageActions = await workflowStageActionRepo.find({
@@ -79,7 +67,8 @@ export class ActionRepository {
79
67
  const mappingIds = stageActions.map((sa) => sa.id);
80
68
 
81
69
  // Step 2: Get template codes with mapping IDs
82
- const workflowActionTemplateMappingRepo = this.reflectionHelper.getRepoService('ActionTemplateMapping');
70
+ const workflowActionTemplateMappingRepo =
71
+ this.reflectionHelper.getRepoService('ActionTemplateMapping');
83
72
 
84
73
  const templateMappings = await workflowActionTemplateMappingRepo.find({
85
74
  where: {
@@ -92,7 +81,8 @@ export class ActionRepository {
92
81
  // Step 3: Fetch template names from frm_wf_comm_template
93
82
  const templateCodeToName: Record<string, string> = {};
94
83
 
95
- const workflowCommTemplateRepo = this.reflectionHelper.getRepoService('CommTemplate');
84
+ const workflowCommTemplateRepo =
85
+ this.reflectionHelper.getRepoService('CommTemplate');
96
86
 
97
87
  if (templateCodes.length > 0) {
98
88
  const templates = await workflowCommTemplateRepo.find({
@@ -136,7 +126,8 @@ export class ActionRepository {
136
126
  }
137
127
 
138
128
  // Step 6: Fetch action details
139
- const workflowActionRepo = this.reflectionHelper.getRepoService('ActionEntity');
129
+ const workflowActionRepo =
130
+ this.reflectionHelper.getRepoService('ActionEntity');
140
131
 
141
132
  const actionResults = await workflowActionRepo
142
133
  .createQueryBuilder()
@@ -147,7 +138,11 @@ export class ActionRepository {
147
138
  'ar.name AS action_requirement',
148
139
  ])
149
140
  .from('frm_wf_action', 'a')
150
- .leftJoin('frm_wf_action_category', 'ac', 'ac.id::text = a.action_category')
141
+ .leftJoin(
142
+ 'frm_wf_action_category',
143
+ 'ac',
144
+ 'ac.id::text = a.action_category',
145
+ )
151
146
  .leftJoin(
152
147
  'frm_list_master_items',
153
148
  'ar',
@@ -181,7 +176,8 @@ export class ActionRepository {
181
176
  action_id?: number,
182
177
  ) {
183
178
  // Step 1: Get all action_ids for the provided stage_id
184
- let stageActionMappingRepo = this.reflectionHelper.getRepoService('StageActionMapping');
179
+ let stageActionMappingRepo =
180
+ this.reflectionHelper.getRepoService('StageActionMapping');
185
181
 
186
182
  const stageActions = await stageActionMappingRepo.find({
187
183
  where: {
@@ -207,8 +203,8 @@ export class ActionRepository {
207
203
  const actionRepo = this.reflectionHelper.getRepoService('ActionEntity');
208
204
  actionResults = await actionRepo.find({
209
205
  where: {
210
- id: In(actionIds)
211
- }
206
+ id: In(actionIds),
207
+ },
212
208
  });
213
209
 
214
210
  // Step 3: Format result
@@ -251,46 +247,47 @@ export class ActionRepository {
251
247
  const actionRepo = this.reflectionHelper.getRepoService('ActionEntity');
252
248
 
253
249
  const actions = await actionRepo
254
- .createQueryBuilder("a")
250
+ .createQueryBuilder('a')
255
251
  .select([
256
- "a.id AS action_id",
257
- "a.name AS action_name",
258
- "a.reason_code AS action_reason_code",
259
- "a.default_reason_code AS default_reason_code",
260
- "a.default_value AS default_value",
261
- "a.mode AS mode",
262
- "a.action_category AS action_category_id",
263
- "ac.reason_code AS category_reason_code",
264
- "ac.modalname AS modalname",
265
- "ac.logo AS logo",
266
- "ac.name AS action_category_name",
267
- "a.dependent_action_id AS dependent_action_id",
252
+ 'a.id AS action_id',
253
+ 'a.name AS action_name',
254
+ 'a.reason_code AS action_reason_code',
255
+ 'a.default_reason_code AS default_reason_code',
256
+ 'a.default_value AS default_value',
257
+ 'a.mode AS mode',
258
+ 'a.action_category AS action_category_id',
259
+ 'ac.reason_code AS category_reason_code',
260
+ 'ac.modalname AS modalname',
261
+ 'ac.logo AS logo',
262
+ 'ac.name AS action_category_name',
263
+ 'a.dependent_action_id AS dependent_action_id',
268
264
  ])
269
265
  .leftJoin(
270
- "frm_wf_action_category",
271
- "ac",
272
- "ac.id = a.action_category::bigint"
266
+ 'frm_wf_action_category',
267
+ 'ac',
268
+ 'ac.id = a.action_category::bigint',
273
269
  )
274
- .where("a.organization_id = :orgId", { orgId: organization_id })
275
- .andWhere("a.id IN (:...actionIds)", { actionIds })
276
- .orderBy("a.sequence", "ASC")
270
+ .where('a.organization_id = :orgId', { orgId: organization_id })
271
+ .andWhere('a.id IN (:...actionIds)', { actionIds })
272
+ .orderBy('a.sequence', 'ASC')
277
273
  .getRawMany();
278
274
 
279
275
  // Step 3: Fetch action_data
280
- const actionDataRepo = this.reflectionHelper.getRepoService('ActionDataEntity');
276
+ const actionDataRepo =
277
+ this.reflectionHelper.getRepoService('ActionDataEntity');
281
278
 
282
279
  const actionData = await actionDataRepo
283
- .createQueryBuilder("ad")
280
+ .createQueryBuilder('ad')
284
281
  .select([
285
- "ad.action_id AS action_id",
286
- "ad.is_current AS is_current",
287
- "ad.is_mandatory AS is_mandatory",
288
- "ad.is_done AS is_done",
282
+ 'ad.action_id AS action_id',
283
+ 'ad.is_current AS is_current',
284
+ 'ad.is_mandatory AS is_mandatory',
285
+ 'ad.is_done AS is_done',
289
286
  ])
290
- .where("ad.stage_id = :stageId", { stageId: stage_id })
291
- .andWhere("ad.action_id IN (:...actionIds)", { actionIds })
292
- .andWhere("ad.mapped_entity_id = :mapped_entity_id", { mapped_entity_id })
293
- .andWhere("ad.mapped_entity_type = :mapped_entity_type", {
287
+ .where('ad.stage_id = :stageId', { stageId: stage_id })
288
+ .andWhere('ad.action_id IN (:...actionIds)', { actionIds })
289
+ .andWhere('ad.mapped_entity_id = :mapped_entity_id', { mapped_entity_id })
290
+ .andWhere('ad.mapped_entity_type = :mapped_entity_type', {
294
291
  mapped_entity_type,
295
292
  })
296
293
  .getRawMany();
@@ -298,8 +295,8 @@ export class ActionRepository {
298
295
  const actionIdToData = actionData.reduce((acc, row) => {
299
296
  acc[row.action_id] = {
300
297
  is_current: row.is_current === 'Y',
301
- is_mandatory: row.is_mandatory === 1,
302
- is_done: row.is_done === 1,
298
+ is_mandatory: row.is_mandatory,
299
+ is_done: row.is_done,
303
300
  };
304
301
  return acc;
305
302
  }, {});
@@ -323,10 +320,10 @@ export class ActionRepository {
323
320
  name: row.action_category_name,
324
321
  reason_code,
325
322
  default_reason_code: row.default_reason_code,
326
- is_default: row.default_value === 1,
327
- is_current: data?.is_current ?? false,
328
- is_done: data?.is_done ?? false,
329
- is_mandatory: data?.is_mandatory ?? false,
323
+ is_default: row.default_value,
324
+ is_current: data?.is_current,
325
+ is_done: data?.is_done,
326
+ is_mandatory: data?.is_mandatory,
330
327
  };
331
328
  });
332
329
 
@@ -1,6 +1,6 @@
1
1
  import { Injectable, NotFoundException } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
- import { DataSource, Repository } from 'typeorm';
3
+ import { Repository } from 'typeorm';
4
4
  import { CommTemplate } from '../entity/comm-template.entity';
5
5
  import { TemplateAttach } from '../entity/template-attach-mapper.entity';
6
6
  import { MediaDataService } from 'src/module/meta/service/media-data.service';
@@ -14,9 +14,9 @@ export class CommTemplateRepository {
14
14
  @InjectRepository(TemplateAttach)
15
15
  private readonly templateAttachEntity: Repository<TemplateAttach>,
16
16
  private readonly mediaDataService: MediaDataService,
17
- private readonly dataSource: DataSource,
18
17
  private readonly reflectionHelper: ReflectionHelper,
19
- ) {}
18
+ ) {
19
+ }
20
20
 
21
21
  async getAllCommTemplate(
22
22
  entity_type: string,
@@ -35,21 +35,27 @@ export class CommTemplateRepository {
35
35
  where: {
36
36
  id: action_id,
37
37
  organization_id: organization_id,
38
- }
39
- })
38
+ },
39
+ });
40
40
 
41
41
  if (!actionResult) {
42
42
  throw new Error('Invalid action_id');
43
43
  }
44
44
 
45
45
  is_template = actionResult.is_template;
46
- await this.dataSource.query(
47
- `UPDATE frm_wf_comm_template
48
- SET is_template = $1
49
- WHERE mapped_entity_type = $2
50
- AND organization_id = $3 AND level_id = $4 AND level_type=$5`,
51
- [is_template, entity_type, organization_id, level_id, level_type],
52
- );
46
+ await this.commTemplateRepository.find({
47
+ where: {},
48
+ });
49
+
50
+ await this.commTemplateRepository
51
+ .createQueryBuilder()
52
+ .update()
53
+ .set({ is_template: Boolean(is_template) })
54
+ .where('mapped_entity_type = :entityType', { entity_type })
55
+ .andWhere('organization_id = :orgId', { orgId: organization_id })
56
+ .andWhere('level_id = :levelId', { levelId: level_id })
57
+ .andWhere('level_type = :levelType', { levelType: level_type })
58
+ .execute();
53
59
  }
54
60
 
55
61
  const whereCondition: any = {
@@ -145,7 +151,7 @@ export class CommTemplateRepository {
145
151
  async findByCodeAndLevelIdAndLevelTypeAndAppCode(code: string, level_id: string,
146
152
  level_type: string, appcode: string) {
147
153
  return await this.commTemplateRepository.findOne({
148
- where: {code, level_id, level_type, appcode}
154
+ where: { code, level_id, level_type, appcode },
149
155
  });
150
156
  }
151
157
  }