rez_core 2.1.144 → 2.1.145

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 (36) hide show
  1. package/dist/constant/global.constant.d.ts +1 -0
  2. package/dist/constant/global.constant.js +2 -1
  3. package/dist/constant/global.constant.js.map +1 -1
  4. package/dist/module/enterprise/repository/school.repository.js +18 -2
  5. package/dist/module/enterprise/repository/school.repository.js.map +1 -1
  6. package/dist/module/workflow/controller/action.controller.d.ts +3 -0
  7. package/dist/module/workflow/controller/action.controller.js +14 -0
  8. package/dist/module/workflow/controller/action.controller.js.map +1 -1
  9. package/dist/module/workflow/controller/entity-modification.controller.d.ts +8 -0
  10. package/dist/module/workflow/controller/entity-modification.controller.js +44 -0
  11. package/dist/module/workflow/controller/entity-modification.controller.js.map +1 -0
  12. package/dist/module/workflow/entity/action.entity.d.ts +1 -0
  13. package/dist/module/workflow/entity/action.entity.js +4 -0
  14. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  15. package/dist/module/workflow/entity/entity-modification.entity.d.ts +13 -0
  16. package/dist/module/workflow/entity/entity-modification.entity.js +63 -0
  17. package/dist/module/workflow/entity/entity-modification.entity.js.map +1 -0
  18. package/dist/module/workflow/service/action.service.d.ts +1 -0
  19. package/dist/module/workflow/service/action.service.js +24 -0
  20. package/dist/module/workflow/service/action.service.js.map +1 -1
  21. package/dist/module/workflow/service/entity-modification.service.d.ts +8 -0
  22. package/dist/module/workflow/service/entity-modification.service.js +52 -0
  23. package/dist/module/workflow/service/entity-modification.service.js.map +1 -0
  24. package/dist/module/workflow/workflow.module.js +10 -0
  25. package/dist/module/workflow/workflow.module.js.map +1 -1
  26. package/dist/tsconfig.build.tsbuildinfo +1 -1
  27. package/package.json +1 -1
  28. package/src/constant/global.constant.ts +2 -0
  29. package/src/module/enterprise/repository/school.repository.ts +23 -2
  30. package/src/module/workflow/controller/action.controller.ts +11 -0
  31. package/src/module/workflow/controller/entity-modification.controller.ts +35 -0
  32. package/src/module/workflow/entity/action.entity.ts +3 -0
  33. package/src/module/workflow/entity/entity-modification.entity.ts +38 -0
  34. package/src/module/workflow/service/action.service.ts +30 -0
  35. package/src/module/workflow/service/entity-modification.service.ts +67 -0
  36. package/src/module/workflow/workflow.module.ts +11 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.144",
3
+ "version": "2.1.145",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -50,3 +50,5 @@ export const COMM_TEMPLATE = 'TEM';
50
50
  export const ACTION_TEMPLATE_MAPPING = 'ATMP';
51
51
  export const WORKFLOW_DATA = 'WFDT';
52
52
  export const STAGE_MOVEMENT_DATA = 'STMV';
53
+
54
+ export const ENTITY_MODIFICATION = 'ENMD';
@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { DataSource, Repository } from 'typeorm';
4
4
  import { SchoolData } from '../entity/school.entity';
5
5
  import { UserRoleMapping } from 'src/module/user/entity/user-role-mapping.entity';
6
+ import { STATUS_INACTIVE } from 'src/constant/global.constant';
6
7
 
7
8
  @Injectable()
8
9
  export class SchoolRepository {
@@ -39,6 +40,16 @@ export class SchoolRepository {
39
40
  currentORGLevel_id = org_id;
40
41
  }
41
42
 
43
+ const resolvedInactiveStatus = await this.dataSource
44
+ .createQueryBuilder()
45
+ .select('*')
46
+ .from('cr_list_master_items', 'cli')
47
+ .where('cli.code = :code AND cli.organization_id = :orgId', {
48
+ code: STATUS_INACTIVE,
49
+ orgId: org_id,
50
+ })
51
+ .getRawOne();
52
+
42
53
  if (hasOrgAccess.length > 0) {
43
54
  const schools = await this.dataSource
44
55
  .createQueryBuilder()
@@ -129,9 +140,14 @@ export class SchoolRepository {
129
140
  })
130
141
  .getRawOne();
131
142
 
143
+ const finalSchoolName =
144
+ schoolStatus?.id === resolvedInactiveStatus?.id
145
+ ? `${school_name} [INACTIVE]`
146
+ : school_name;
147
+
132
148
  result[org_id].brands[brand_id].schools.push({
133
149
  school_id,
134
- school_name,
150
+ school_name: finalSchoolName,
135
151
  school_location,
136
152
  status: schoolStatus ? schoolStatus.name : school_status,
137
153
  type: 'School',
@@ -225,13 +241,18 @@ export class SchoolRepository {
225
241
  };
226
242
  }
227
243
 
244
+ const finalSchoolName =
245
+ school_status === resolvedInactiveStatus?.id
246
+ ? `${school_name} [INACTIVE]`
247
+ : school_name;
248
+
228
249
  if (
229
250
  school_id &&
230
251
  !result[brand_id].schools.some((s) => s.school_id === school_id)
231
252
  ) {
232
253
  result[brand_id].schools.push({
233
254
  school_id,
234
- school_name,
255
+ school_name: finalSchoolName,
235
256
  school_location,
236
257
  status: school_status,
237
258
  type: 'School',
@@ -41,4 +41,15 @@ export class ActionController {
41
41
  );
42
42
  return result;
43
43
  }
44
+
45
+ @Post('/getActions')
46
+ @HttpCode(HttpStatus.OK)
47
+ async getActions(
48
+ @Req() req: Request & { user: any },
49
+ @Body('workflow_id') workflow_id: number,
50
+ ) {
51
+ const loggedInUser = req.user.userData;
52
+ const result = this.actionService.getActions(loggedInUser, workflow_id);
53
+ return result;
54
+ }
44
55
  }
@@ -0,0 +1,35 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Get,
5
+ HttpCode,
6
+ HttpStatus,
7
+ Inject,
8
+ Post,
9
+ Req,
10
+ UseGuards,
11
+ } from '@nestjs/common';
12
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
13
+ import { EntityModificationService } from '../service/entity-modification.service';
14
+
15
+ @Controller('/entity-modification')
16
+ @UseGuards(JwtAuthGuard)
17
+ export class EntityModificationController {
18
+ constructor(
19
+ @Inject('EntityModificationService')
20
+ private readonly entityModificationService: EntityModificationService,
21
+ ) {}
22
+
23
+ @Post('/logModification')
24
+ @HttpCode(HttpStatus.OK)
25
+ async logModification(
26
+ @Body() modificationData: any,
27
+ @Req() req: Request & { user: any },
28
+ ) {
29
+ const loggedInUser = req.user.userData;
30
+ return await this.entityModificationService.logModification(
31
+ modificationData,
32
+ loggedInUser,
33
+ );
34
+ }
35
+ }
@@ -18,6 +18,9 @@ export class ActionEntity extends BaseEntity {
18
18
  @Column({ type: 'varchar', nullable: true })
19
19
  action_requirement: string;
20
20
 
21
+ @Column({ type: 'varchar', nullable: true })
22
+ template: string;
23
+
21
24
  @Column({ type: 'varchar', nullable: true })
22
25
  reason_code: string;
23
26
 
@@ -0,0 +1,38 @@
1
+ import { ENTITY_MODIFICATION } from 'src/constant/global.constant';
2
+ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
3
+ import { Column, Entity } from 'typeorm';
4
+
5
+ @Entity({ name: 'cr_wf_entity_modification' })
6
+ export class EntityModification extends BaseEntity {
7
+ constructor() {
8
+ super();
9
+ this.entity_type = ENTITY_MODIFICATION;
10
+ }
11
+
12
+ @Column({ type: 'int', nullable: true })
13
+ mapped_entity_id: number;
14
+
15
+ @Column({ type: 'varchar', nullable: true })
16
+ mapped_entity_type: string;
17
+
18
+ @Column({ type: 'varchar', nullable: true })
19
+ mode: string;
20
+
21
+ @Column({ type: 'int', nullable: true })
22
+ stage_id: number;
23
+
24
+ @Column({ type: 'int', nullable: true })
25
+ action_id: number;
26
+
27
+ @Column({ type: 'varchar', nullable: true })
28
+ attribute_key: string;
29
+
30
+ @Column({ type: 'varchar', nullable: true })
31
+ current_value: string;
32
+
33
+ @Column({ type: 'varchar', nullable: true })
34
+ new_value: string;
35
+
36
+ @Column({ type: 'varchar', nullable: true })
37
+ reason_code: string;
38
+ }
@@ -209,4 +209,34 @@ export class ActionService extends EntityServiceImpl {
209
209
  value: row.name,
210
210
  }));
211
211
  }
212
+
213
+ async getActions(loggedInUser: UserData, workflow_id: number) {
214
+ const { organization_id } = loggedInUser;
215
+
216
+ const result = await this.dataSource.query(
217
+ `
218
+ SELECT
219
+ a.name AS action_name,
220
+ ac.name AS action_category,
221
+ ar.name AS action_requirement,
222
+ 'Email Template' AS template
223
+
224
+ FROM cr_wf_action a
225
+
226
+ LEFT JOIN cr_wf_action_category ac
227
+ ON ac.id = a.action_cat_id
228
+
229
+ LEFT JOIN cr_list_master_items ar
230
+ ON ar.id = a.action_requirement
231
+ AND ar.listtype = 'ACRQ'
232
+ AND ar.organization_id = ?
233
+
234
+ WHERE a.organization_id = ?
235
+ AND a.workflow_id = ?
236
+ `,
237
+ [organization_id, organization_id, workflow_id],
238
+ );
239
+
240
+ return result;
241
+ }
212
242
  }
@@ -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
+ }
@@ -30,6 +30,10 @@ import { StageGroupController } from './controller/stage-group.controller';
30
30
  import { StageController } from './controller/stage.controller';
31
31
  import { StageRepository } from './repository/stage.repository';
32
32
  import { ActionController } from './controller/action.controller';
33
+ import { EntityController } from '../meta/controller/entity.controller';
34
+ import { EntityModificationService } from './service/entity-modification.service';
35
+ import { EntityModification } from './entity/entity-modification.entity';
36
+ import { EntityModificationController } from './controller/entity-modification.controller';
33
37
 
34
38
  @Module({
35
39
  imports: [
@@ -42,6 +46,7 @@ import { ActionController } from './controller/action.controller';
42
46
  CommTemplate,
43
47
  ActionTemplateMapping,
44
48
  StageActionMapping,
49
+ EntityModification,
45
50
  ]),
46
51
  EntityModule,
47
52
  ListMasterModule,
@@ -57,6 +62,10 @@ import { ActionController } from './controller/action.controller';
57
62
  { provide: 'StageService', useClass: StageService },
58
63
  { provide: 'StageGroupService', useClass: StageGroupService },
59
64
  { provide: 'WorkflowService', useClass: WorkflowService },
65
+ {
66
+ provide: 'EntityModificationService',
67
+ useClass: EntityModificationService,
68
+ },
60
69
  WorkflowListMasterService,
61
70
  ActionTemplateMappingService,
62
71
  WorkflowRepository,
@@ -72,6 +81,7 @@ import { ActionController } from './controller/action.controller';
72
81
  'ActionService',
73
82
  'StageService',
74
83
  'StageGroupService',
84
+ 'EntityModificationService',
75
85
  WorkflowRepository,
76
86
  StageGroupRepository,
77
87
  StageRepository,
@@ -84,6 +94,7 @@ import { ActionController } from './controller/action.controller';
84
94
  StageGroupController,
85
95
  StageController,
86
96
  ActionController,
97
+ EntityModificationController,
87
98
  ],
88
99
  })
89
100
  export class WorkflowModule {}