rez_core 2.1.143 → 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 (54) 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/controller/workflow.controller.js +1 -1
  13. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  14. package/dist/module/workflow/entity/action.entity.d.ts +1 -0
  15. package/dist/module/workflow/entity/action.entity.js +4 -0
  16. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  17. package/dist/module/workflow/entity/entity-modification.entity.d.ts +13 -0
  18. package/dist/module/workflow/entity/entity-modification.entity.js +63 -0
  19. package/dist/module/workflow/entity/entity-modification.entity.js.map +1 -0
  20. package/dist/module/workflow/repository/comm-template.repository.d.ts +1 -0
  21. package/dist/module/workflow/repository/comm-template.repository.js +12 -0
  22. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  23. package/dist/module/workflow/service/action.service.d.ts +1 -0
  24. package/dist/module/workflow/service/action.service.js +24 -0
  25. package/dist/module/workflow/service/action.service.js.map +1 -1
  26. package/dist/module/workflow/service/comm-template.service.d.ts +1 -0
  27. package/dist/module/workflow/service/comm-template.service.js +4 -0
  28. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  29. package/dist/module/workflow/service/entity-modification.service.d.ts +8 -0
  30. package/dist/module/workflow/service/entity-modification.service.js +52 -0
  31. package/dist/module/workflow/service/entity-modification.service.js.map +1 -0
  32. package/dist/module/workflow/service/stage-group.service.d.ts +3 -1
  33. package/dist/module/workflow/service/stage-group.service.js +6 -3
  34. package/dist/module/workflow/service/stage-group.service.js.map +1 -1
  35. package/dist/module/workflow/service/workflow.service.js +14 -4
  36. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  37. package/dist/module/workflow/workflow.module.js +10 -0
  38. package/dist/module/workflow/workflow.module.js.map +1 -1
  39. package/dist/tsconfig.build.tsbuildinfo +1 -1
  40. package/package.json +1 -1
  41. package/src/constant/global.constant.ts +2 -0
  42. package/src/module/enterprise/repository/school.repository.ts +23 -2
  43. package/src/module/workflow/controller/action.controller.ts +11 -0
  44. package/src/module/workflow/controller/entity-modification.controller.ts +35 -0
  45. package/src/module/workflow/controller/workflow.controller.ts +1 -1
  46. package/src/module/workflow/entity/action.entity.ts +3 -0
  47. package/src/module/workflow/entity/entity-modification.entity.ts +38 -0
  48. package/src/module/workflow/repository/comm-template.repository.ts +19 -0
  49. package/src/module/workflow/service/action.service.ts +30 -0
  50. package/src/module/workflow/service/comm-template.service.ts +16 -0
  51. package/src/module/workflow/service/entity-modification.service.ts +67 -0
  52. package/src/module/workflow/service/stage-group.service.ts +5 -4
  53. package/src/module/workflow/service/workflow.service.ts +25 -7
  54. 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.143",
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
+ }
@@ -44,7 +44,7 @@ export class WorkflowController {
44
44
  }
45
45
  SS;
46
46
 
47
- @Put('/updateSequence')
47
+ @Post('/updateSequence')
48
48
  @HttpCode(HttpStatus.OK)
49
49
  async updateSequence(@Body() body: any, @Req() req: Request & { user: any }) {
50
50
  const loggedInUser = req.user?.userData;
@@ -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
+ }
@@ -19,4 +19,23 @@ export class CommTemplateRepository {
19
19
  },
20
20
  });
21
21
  }
22
+
23
+ async getTemplateByCode(
24
+ entity_type: string,
25
+ code: string,
26
+ loggedInUser,
27
+ ): Promise<CommTemplate | null> {
28
+ const template = await this.commTemplateRepository.findOne({
29
+ where: {
30
+ entity_type: entity_type,
31
+ code: code,
32
+ },
33
+ });
34
+
35
+ if (!template) {
36
+ throw new NotFoundException(`Template with code ${code} not found`);
37
+ }
38
+
39
+ return template;
40
+ }
22
41
  }
@@ -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
  }
@@ -8,6 +8,22 @@ export class CommTemplateService extends EntityServiceImpl {
8
8
  super();
9
9
  }
10
10
 
11
+ async getEntityData(
12
+ entityType: string,
13
+ id: number,
14
+ loggedInUser,
15
+ ): Promise<any> {
16
+ //TODO: check if current level_id and levl_type has that code if not go to parent level
17
+
18
+ const getTemplate = await this.commTemplateRepository.getTemplateByCode(
19
+ entityType,
20
+ id.toString(),
21
+ loggedInUser,
22
+ );
23
+
24
+ return getTemplate;
25
+ }
26
+
11
27
  async getAllCommTemplate(entity_type: string, loggedInUser) {
12
28
  const commTemplateData =
13
29
  await this.commTemplateRepository.getAllCommTemplate(
@@ -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
+ }
@@ -4,6 +4,7 @@ import { StageGroupRepository } from '../repository/stage-group.repository';
4
4
  import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
5
5
  import { UserData } from 'src/module/user/entity/user.entity';
6
6
  import { StageService } from './stage.service';
7
+ import { DataSource } from 'typeorm';
7
8
 
8
9
  @Injectable()
9
10
  export class StageGroupService extends EntityServiceImpl {
@@ -11,6 +12,7 @@ export class StageGroupService extends EntityServiceImpl {
11
12
  private readonly stageGroupRepository: StageGroupRepository,
12
13
  @Inject('StageService')
13
14
  private readonly stageService: StageService,
15
+ private readonly dataSource: DataSource,
14
16
  ) {
15
17
  super();
16
18
  }
@@ -46,10 +48,9 @@ export class StageGroupService extends EntityServiceImpl {
46
48
  id: number,
47
49
  loggedInUser: UserData,
48
50
  ): Promise<any> {
49
- const getAllStage = await this.stageService.getAllStage(
50
- id,
51
- loggedInUser.level_id,
52
- loggedInUser.level_type,
51
+ const getAllStage = await this.dataSource.query(
52
+ `SELECT id FROM cr_wf_stage WHERE stage_group_id = ? AND level_id =? AND level_type = ?`,
53
+ [id, loggedInUser.level_id, loggedInUser.level_type],
53
54
  );
54
55
 
55
56
  if (getAllStage.length > 0) {
@@ -1,3 +1,4 @@
1
+ import { get } from 'http';
1
2
  import { BadRequestException, Inject, Injectable } from '@nestjs/common';
2
3
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
4
  import { DataSource, In } from 'typeorm';
@@ -106,17 +107,34 @@ export class WorkflowService extends EntityServiceImpl {
106
107
  id: number,
107
108
  loggedInUser: UserData,
108
109
  ): Promise<any> {
109
- const getAllStage = await this.stageGroupRepository.getAllStageGroup(
110
- id,
111
- loggedInUser.level_id,
112
- loggedInUser.level_type,
110
+ const getWorkflow = await this.getEntityData(entityType, id, loggedInUser);
111
+
112
+ if (!getWorkflow) {
113
+ throw new BadRequestException('Workflow not found');
114
+ }
115
+
116
+ if ((getWorkflow as Workflow).is_default) {
117
+ throw new BadRequestException(
118
+ 'Cannot delete workflow because it is default.',
119
+ );
120
+ }
121
+
122
+ if ((getWorkflow as Workflow).is_factory) {
123
+ throw new BadRequestException(
124
+ 'Cannot delete workflow because it is factory.',
125
+ );
126
+ }
127
+
128
+ const getAllStageGroup = await this.dataSource.query(
129
+ `SELECT id FROM cr_wf_stage_group WHERE workflow_id = ? AND level_id = ? AND level_type = ?`,
130
+ [id, loggedInUser.level_id, loggedInUser.level_type],
113
131
  );
114
132
 
115
- if (getAllStage.length > 0) {
116
- for (const stage of getAllStage) {
133
+ if (getAllStageGroup.length > 0) {
134
+ for (const stageGroup of getAllStageGroup) {
117
135
  await this.stateGroupService.deleteEntity(
118
136
  'STGP',
119
- stage.id,
137
+ stageGroup.id,
120
138
  loggedInUser,
121
139
  );
122
140
  }
@@ -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 {}