rez_core 2.1.138 → 2.1.140

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/filter/controller/filter.controller.d.ts +1 -1
  2. package/dist/module/filter/controller/filter.controller.js +7 -4
  3. package/dist/module/filter/controller/filter.controller.js.map +1 -1
  4. package/dist/module/filter/dto/filter-request.dto.d.ts +1 -0
  5. package/dist/module/filter/service/filter.service.js +23 -2
  6. package/dist/module/filter/service/filter.service.js.map +1 -1
  7. package/dist/module/workflow/controller/comm-template.controller.d.ts +11 -0
  8. package/dist/module/workflow/controller/comm-template.controller.js +44 -0
  9. package/dist/module/workflow/controller/comm-template.controller.js.map +1 -0
  10. package/dist/module/workflow/controller/stage-group.controller.d.ts +10 -0
  11. package/dist/module/workflow/controller/stage-group.controller.js +43 -0
  12. package/dist/module/workflow/controller/stage-group.controller.js.map +1 -0
  13. package/dist/module/workflow/controller/stage.controller.d.ts +10 -0
  14. package/dist/module/workflow/controller/stage.controller.js +43 -0
  15. package/dist/module/workflow/controller/stage.controller.js.map +1 -0
  16. package/dist/module/workflow/controller/workflow.controller.d.ts +18 -9
  17. package/dist/module/workflow/controller/workflow.controller.js +25 -13
  18. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  19. package/dist/module/workflow/entity/action.entity.d.ts +4 -1
  20. package/dist/module/workflow/entity/action.entity.js +20 -8
  21. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  22. package/dist/module/workflow/entity/stage-group.entity.d.ts +1 -1
  23. package/dist/module/workflow/entity/stage-group.entity.js +1 -1
  24. package/dist/module/workflow/entity/stage-group.entity.js.map +1 -1
  25. package/dist/module/workflow/entity/stage.entity.d.ts +1 -2
  26. package/dist/module/workflow/entity/stage.entity.js +1 -5
  27. package/dist/module/workflow/entity/stage.entity.js.map +1 -1
  28. package/dist/module/workflow/entity/workflow.entity.d.ts +3 -0
  29. package/dist/module/workflow/entity/workflow.entity.js +12 -0
  30. package/dist/module/workflow/entity/workflow.entity.js.map +1 -1
  31. package/dist/module/workflow/repository/comm-template.repository.d.ts +7 -0
  32. package/dist/module/workflow/repository/comm-template.repository.js +39 -0
  33. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -0
  34. package/dist/module/workflow/repository/stage-group.repository.d.ts +7 -0
  35. package/dist/module/workflow/repository/stage-group.repository.js +50 -0
  36. package/dist/module/workflow/repository/stage-group.repository.js.map +1 -0
  37. package/dist/module/workflow/repository/stage.repository.d.ts +7 -0
  38. package/dist/module/workflow/repository/stage.repository.js +50 -0
  39. package/dist/module/workflow/repository/stage.repository.js.map +1 -0
  40. package/dist/module/workflow/repository/workflow.repository.d.ts +9 -1
  41. package/dist/module/workflow/repository/workflow.repository.js +38 -6
  42. package/dist/module/workflow/repository/workflow.repository.js.map +1 -1
  43. package/dist/module/workflow/service/action.service.d.ts +2 -0
  44. package/dist/module/workflow/service/action.service.js +39 -7
  45. package/dist/module/workflow/service/action.service.js.map +1 -1
  46. package/dist/module/workflow/service/comm-template.service.d.ts +8 -2
  47. package/dist/module/workflow/service/comm-template.service.js +18 -3
  48. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  49. package/dist/module/workflow/service/stage-group.service.d.ts +8 -0
  50. package/dist/module/workflow/service/stage-group.service.js +19 -1
  51. package/dist/module/workflow/service/stage-group.service.js.map +1 -1
  52. package/dist/module/workflow/service/stage.service.d.ts +7 -5
  53. package/dist/module/workflow/service/stage.service.js +12 -18
  54. package/dist/module/workflow/service/stage.service.js.map +1 -1
  55. package/dist/module/workflow/service/workflow.service.d.ts +22 -3
  56. package/dist/module/workflow/service/workflow.service.js +65 -39
  57. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  58. package/dist/module/workflow/workflow.module.js +22 -2
  59. package/dist/module/workflow/workflow.module.js.map +1 -1
  60. package/dist/tsconfig.build.tsbuildinfo +1 -1
  61. package/package.json +1 -1
  62. package/src/module/filter/controller/filter.controller.ts +10 -4
  63. package/src/module/filter/dto/filter-request.dto.ts +1 -0
  64. package/src/module/filter/service/filter.service.ts +34 -2
  65. package/src/module/workflow/controller/comm-template.controller.ts +31 -0
  66. package/src/module/workflow/controller/stage-group.controller.ts +33 -0
  67. package/src/module/workflow/controller/stage.controller.ts +33 -0
  68. package/src/module/workflow/controller/workflow.controller.ts +18 -11
  69. package/src/module/workflow/entity/action.entity.ts +10 -1
  70. package/src/module/workflow/entity/stage-group.entity.ts +1 -1
  71. package/src/module/workflow/entity/stage.entity.ts +1 -4
  72. package/src/module/workflow/entity/workflow.entity.ts +9 -0
  73. package/src/module/workflow/repository/comm-template.repository.ts +22 -0
  74. package/src/module/workflow/repository/stage-group.repository.ts +46 -0
  75. package/src/module/workflow/repository/stage.repository.ts +47 -0
  76. package/src/module/workflow/repository/workflow.repository.ts +40 -2
  77. package/src/module/workflow/service/action.service.ts +85 -14
  78. package/src/module/workflow/service/comm-template.service.ts +21 -2
  79. package/src/module/workflow/service/stage-group.service.ts +35 -2
  80. package/src/module/workflow/service/stage.service.ts +24 -33
  81. package/src/module/workflow/service/workflow.service.ts +100 -47
  82. package/src/module/workflow/workflow.module.ts +23 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.138",
3
+ "version": "2.1.140",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -26,11 +26,16 @@ export class FilterController {
26
26
  @UseGuards(JwtAuthGuard)
27
27
  async applyFilter(
28
28
  @Body() body: any,
29
- @Query('page', ParseIntPipe) page: number = 1,
30
- @Query('size', ParseIntPipe) size: number = 10,
29
+ @Query('page', ParseIntPipe) page = 1,
30
+ @Query('size', ParseIntPipe) size = 10,
31
31
  @Req() req: Request & { user: any },
32
+ @Query() queryParams: Record<string, string>,
32
33
  ) {
33
- const userData = req.user.userData;
34
+ const loggedInUser = req.user.userData;
35
+
36
+ // Remove page and size from queryParams
37
+ const { page: _p, size: _s, ...otherQueryParams } = queryParams;
38
+
34
39
  const {
35
40
  entity_type,
36
41
  quickFilter,
@@ -49,7 +54,8 @@ export class FilterController {
49
54
  sortby,
50
55
  page,
51
56
  size,
52
- loggedInUser: userData,
57
+ loggedInUser,
58
+ queryParams: otherQueryParams, // only remaining query params
53
59
  });
54
60
  }
55
61
 
@@ -26,4 +26,5 @@ export interface FilterRequestDto {
26
26
  page?: number;
27
27
  size?: number;
28
28
  loggedInUser: UserData;
29
+ queryParams?: Record<string, string>;
29
30
  }
@@ -78,8 +78,10 @@ export class FilterService {
78
78
  tabs,
79
79
  sortby,
80
80
  loggedInUser,
81
+ queryParams,
81
82
  } = dto;
82
83
 
84
+ // abstract user details
83
85
  const {
84
86
  level_type,
85
87
  level_id,
@@ -88,15 +90,18 @@ export class FilterService {
88
90
  organization_id,
89
91
  } = loggedInUser || {};
90
92
 
91
- // Fetch meta
93
+ // Fetch meta from entity table service
92
94
  const entityMeta = await this.entityTableService.getEntityData(
93
95
  entity_type,
94
96
  loggedInUser,
95
97
  );
96
98
  const tableName = entityMeta?.data_source; // data_souce is the table name
97
- if (!tableName)
99
+
100
+ if (!tableName) {
98
101
  throw new BadRequestException(`Invalid entity_type: ${entity_type}`);
102
+ }
99
103
 
104
+ // get table meta from cr_entity_table
100
105
  const getTableMeta =
101
106
  await this.entityTableService.findByEntityTypeAndListTypeAndDisplayType(
102
107
  entity_type,
@@ -110,6 +115,7 @@ export class FilterService {
110
115
  `Table meta not found for entity_type: ${entity_type}`,
111
116
  );
112
117
  }
118
+
113
119
  const getTableColumnMeta =
114
120
  await this.entityTableColumnService.findByParentIdAndParentType(
115
121
  getTableMeta.id,
@@ -153,6 +159,32 @@ export class FilterService {
153
159
  });
154
160
  }
155
161
 
162
+ // andWhere search with attributeName && attributeValue
163
+ if (queryParams) {
164
+ Object.entries(queryParams).forEach(([key, value]) => {
165
+ if (!value) return;
166
+
167
+ // Handle custom attributeName/attributeValue
168
+ if (key === 'attributeName' && queryParams['attributeValue']) {
169
+ const attrName = value;
170
+ const attrValue = queryParams['attributeValue'];
171
+
172
+ baseWhere.push({
173
+ query: `e.${attrName} = :${attrName}`,
174
+ params: { [attrName]: attrValue },
175
+ });
176
+ }
177
+
178
+ // Ignore attributeValue itself from being added again
179
+ else if (key !== 'attributeValue') {
180
+ baseWhere.push({
181
+ query: `e.${key} = :${key}`,
182
+ params: { [key]: value },
183
+ });
184
+ }
185
+ });
186
+ }
187
+
156
188
  // if (!this.skipAppCodeFilterEntities.includes(entity_type)) {
157
189
  // baseWhere.push({
158
190
  // query: 'e.appcode = :appcode',
@@ -0,0 +1,31 @@
1
+ import {
2
+ Controller,
3
+ Get,
4
+ HttpCode,
5
+ HttpStatus,
6
+ Query,
7
+ Req,
8
+ UseGuards,
9
+ } from '@nestjs/common';
10
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
11
+ import { CommTemplateService } from '../service/comm-template.service';
12
+
13
+ @Controller('/templates')
14
+ @UseGuards(JwtAuthGuard)
15
+ export class CommTemplateController {
16
+ constructor(private readonly commTemplateService: CommTemplateService) {}
17
+
18
+ @Get('/get-comm-template')
19
+ @HttpCode(HttpStatus.OK)
20
+ async getTemplate(
21
+ @Req() req: Request & { user: any },
22
+ @Query('entity_type') entityType?: string,
23
+ ) {
24
+ const loggedInUser = req.user.userData;
25
+ const result = this.commTemplateService.getAllCommTemplate(
26
+ entityType || '',
27
+ loggedInUser,
28
+ );
29
+ return result;
30
+ }
31
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Get,
5
+ Inject,
6
+ Post,
7
+ Req,
8
+ UseGuards,
9
+ } from '@nestjs/common';
10
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
11
+ import { StageGroupService } from '../service/stage-group.service';
12
+
13
+ @Controller('/stage-group')
14
+ @UseGuards(JwtAuthGuard)
15
+ export class StageGroupController {
16
+ constructor(
17
+ @Inject('StageGroupService')
18
+ private readonly stageGroupService: StageGroupService,
19
+ ) {}
20
+
21
+ @Post('/getAllStageGroup')
22
+ async getAllStageGroup(
23
+ @Req() req: Request & { user: any },
24
+ @Body() body: { workflow_id: number },
25
+ ) {
26
+ const { level_id, level_type } = req.user.userData;
27
+ return this.stageGroupService.getAllStageGroup(
28
+ body.workflow_id,
29
+ level_id,
30
+ level_type,
31
+ );
32
+ }
33
+ }
@@ -0,0 +1,33 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Get,
5
+ Inject,
6
+ Post,
7
+ Req,
8
+ UseGuards,
9
+ } from '@nestjs/common';
10
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
11
+ import { StageService } from '../service/stage.service';
12
+
13
+ @Controller('/stage')
14
+ @UseGuards(JwtAuthGuard)
15
+ export class StageController {
16
+ constructor(
17
+ @Inject('StageService')
18
+ private readonly stageGroupService: StageService,
19
+ ) {}
20
+
21
+ @Post('/getAllStage')
22
+ async getAllStage(
23
+ @Req() req: Request & { user: any },
24
+ @Body() body: { stage_group_id: number },
25
+ ) {
26
+ const { level_id, level_type } = req.user.userData;
27
+ return this.stageGroupService.getAllStage(
28
+ body.stage_group_id,
29
+ level_id,
30
+ level_type,
31
+ );
32
+ }
33
+ }
@@ -10,10 +10,10 @@ import {
10
10
  Param,
11
11
  Put,
12
12
  Inject,
13
+ Delete,
13
14
  } from '@nestjs/common';
14
15
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
15
16
  import { WorkflowService } from '../service/workflow.service';
16
- import { Request } from 'express';
17
17
 
18
18
  @Controller('/workflow')
19
19
  @UseGuards(JwtAuthGuard)
@@ -23,18 +23,18 @@ export class WorkflowController {
23
23
  private readonly workflowService: WorkflowService,
24
24
  ) {}
25
25
 
26
- @Post('/getWorkflow')
26
+ @Post('/getAllWorkflows')
27
27
  @HttpCode(HttpStatus.OK)
28
- async getWorkflow(
29
- @Body() body: { entity_type: string },
28
+ async getAllWorkflows(
30
29
  @Req() req: Request & { user: any },
30
+ @Body() body: { entity_type: string },
31
31
  ) {
32
- const loggedInUser = req.user.userData;
33
- const result = await this.workflowService.getAllWorkflow(
32
+ const { level_id, level_type } = req.user.userData;
33
+ return this.workflowService.getAllWorkflows(
34
34
  body.entity_type,
35
- loggedInUser,
35
+ level_id,
36
+ level_type,
36
37
  );
37
- return result;
38
38
  }
39
39
 
40
40
  @Get('/getWorkflowById/:id')
@@ -43,9 +43,16 @@ export class WorkflowController {
43
43
  return this.workflowService.getWorkflowById(id);
44
44
  }
45
45
 
46
- @Post('/getContactDropdown')
46
+ @Delete('/deleteWorkflow/:id')
47
+ @HttpCode(HttpStatus.OK)
48
+ async deleteWorkflow(@Param('id') id: number) {
49
+ return this.workflowService.deleteWorkflowById(id);
50
+ }
51
+
52
+ @Put('/updateSequence')
47
53
  @HttpCode(HttpStatus.OK)
48
- async getLeadContactDropdown(@Body() body: { leadId: number; mode: string }) {
49
- return this.workflowService.getLeadContactDropdown(body.leadId, body.mode);
54
+ async updateSequence(@Body() body: any, @Req() req: Request & { user: any }) {
55
+ const loggedInUser = req.user?.userData;
56
+ return this.workflowService.updateSequence(body, loggedInUser);
50
57
  }
51
58
  }
@@ -3,7 +3,7 @@ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
3
3
  import { Column, Entity } from 'typeorm';
4
4
 
5
5
  @Entity({ name: 'cr_wf_action' })
6
- export class Action extends BaseEntity {
6
+ export class ActionEntity extends BaseEntity {
7
7
  constructor() {
8
8
  super();
9
9
  this.entity_type = ACTION;
@@ -17,4 +17,13 @@ export class Action extends BaseEntity {
17
17
 
18
18
  @Column({ type: 'varchar', nullable: true })
19
19
  action_requirement: string;
20
+
21
+ @Column({ type: 'varchar', nullable: true })
22
+ reason_code: string;
23
+
24
+ @Column({ type: 'varchar', nullable: true })
25
+ default_reason_code: string;
26
+
27
+ @Column({ default: 0, type: 'boolean' })
28
+ default_value: boolean;
20
29
  }
@@ -13,5 +13,5 @@ export class StageGroup extends BaseEntity {
13
13
  workflow_id: number;
14
14
 
15
15
  @Column({ type: 'int', nullable: true })
16
- sortindex: number;
16
+ sequence: number;
17
17
  }
@@ -12,9 +12,6 @@ export class Stage extends BaseEntity {
12
12
  @Column({ type: 'int', nullable: true })
13
13
  stage_group_id: number;
14
14
 
15
- @Column({ type: 'varchar', length: 100, nullable: true })
16
- full_name: string;
17
-
18
15
  @Column({ type: 'int', nullable: true })
19
- sortindex: number;
16
+ sequence: number;
20
17
  }
@@ -11,4 +11,13 @@ export class Workflow extends BaseEntity {
11
11
 
12
12
  @Column({ type: 'varchar', nullable: true })
13
13
  mapped_entity_type: string;
14
+
15
+ @Column({ type: 'boolean', nullable: true })
16
+ is_default: boolean;
17
+
18
+ @Column({ type: 'boolean', nullable: true })
19
+ is_factory: boolean;
20
+
21
+ @Column({ type: 'int', nullable: true })
22
+ sequence: number;
14
23
  }
@@ -0,0 +1,22 @@
1
+ import { Injectable, NotFoundException } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { Workflow } from '../entity/workflow.entity';
4
+ import { Repository } from 'typeorm';
5
+ import { CommTemplate } from '../entity/comm-template.entity';
6
+
7
+ @Injectable()
8
+ export class CommTemplateRepository {
9
+ constructor(
10
+ @InjectRepository(CommTemplate)
11
+ private readonly commTemplateRepository: Repository<CommTemplate>,
12
+ ) {}
13
+
14
+ async getAllCommTemplate(entity_type: string, loggedInUser) {
15
+ return this.commTemplateRepository.find({
16
+ select: ['name', 'code'],
17
+ where: {
18
+ entity_type: entity_type,
19
+ },
20
+ });
21
+ }
22
+ }
@@ -0,0 +1,46 @@
1
+ import {
2
+ BadRequestException,
3
+ Inject,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
7
+ import { StageGroup } from '../entity/stage-group.entity';
8
+ import { InjectRepository } from '@nestjs/typeorm';
9
+ import { Repository } from 'typeorm';
10
+
11
+ @Injectable()
12
+ export class StageGroupRepository {
13
+ constructor(
14
+ @InjectRepository(StageGroup)
15
+ private readonly stageGroupRepository: Repository<StageGroup>,
16
+ ) {}
17
+
18
+ async getAllStageGroup(
19
+ workflow_id: number,
20
+ level_id: string,
21
+ level_type: string,
22
+ ) {
23
+ if (!workflow_id) {
24
+ throw new BadRequestException('workflow_id is required');
25
+ }
26
+
27
+ const result = await this.stageGroupRepository.find({
28
+ where: {
29
+ workflow_id,
30
+ level_id,
31
+ level_type,
32
+ },
33
+ order: {
34
+ sequence: 'ASC', // or 'DESC' if you want reverse order
35
+ },
36
+ });
37
+
38
+ if (!result || result.length === 0) {
39
+ throw new NotFoundException(
40
+ 'No stage groups found for the given workflow ID',
41
+ );
42
+ }
43
+
44
+ return result;
45
+ }
46
+ }
@@ -0,0 +1,47 @@
1
+ import {
2
+ BadRequestException,
3
+ Inject,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
7
+ import { StageGroup } from '../entity/stage-group.entity';
8
+ import { InjectRepository } from '@nestjs/typeorm';
9
+ import { Repository } from 'typeorm';
10
+ import { Stage } from '../entity/stage.entity';
11
+
12
+ @Injectable()
13
+ export class StageRepository {
14
+ constructor(
15
+ @InjectRepository(Stage)
16
+ private readonly stageRepository: Repository<Stage>,
17
+ ) {}
18
+
19
+ async getAllStage(
20
+ stage_group_id: number,
21
+ level_id: string,
22
+ level_type: string,
23
+ ) {
24
+ if (!stage_group_id) {
25
+ throw new BadRequestException('stage_group_id is required');
26
+ }
27
+
28
+ const result = await this.stageRepository.find({
29
+ where: {
30
+ stage_group_id,
31
+ level_id,
32
+ level_type,
33
+ },
34
+ order: {
35
+ sequence: 'ASC', // or 'DESC' if you want reverse order
36
+ },
37
+ });
38
+
39
+ if (!result || result.length === 0) {
40
+ throw new NotFoundException(
41
+ 'No stage found for the given stage group ID',
42
+ );
43
+ }
44
+
45
+ return result;
46
+ }
47
+ }
@@ -1,4 +1,42 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { Injectable, NotFoundException } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { Workflow } from '../entity/workflow.entity';
4
+ import { Repository } from 'typeorm';
2
5
 
3
6
  @Injectable()
4
- export class WorkflowRepsository {}
7
+ export class WorkflowRepository {
8
+ constructor(
9
+ @InjectRepository(Workflow)
10
+ private readonly workflowRepository: Repository<Workflow>,
11
+ ) {}
12
+
13
+ // async getWorkflowById(id: number) {
14
+ // return this.workflowRepository.findOne(id);
15
+ // }
16
+
17
+ async getAllWorkflowsByFilters(
18
+ entity_type: string,
19
+ level_id: string,
20
+ level_type: string,
21
+ ): Promise<Workflow[]> {
22
+ return this.workflowRepository.find({
23
+ where: {
24
+ mapped_entity_type: entity_type,
25
+ level_id,
26
+ level_type,
27
+ },
28
+ });
29
+ }
30
+
31
+ async deleteWorkflowById(id: number) {
32
+ const result = await this.workflowRepository.delete(id);
33
+
34
+ if (result.affected === 0) {
35
+ throw new NotFoundException(`Workflow with ID ${id} not found`);
36
+ }
37
+
38
+ return {
39
+ message: `Workflow has been successfully deleted.`,
40
+ };
41
+ }
42
+ }
@@ -3,6 +3,7 @@ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
3
3
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
4
4
  import { UserData } from 'src/module/user/entity/user.entity';
5
5
  import { DataSource, EntityManager } from 'typeorm';
6
+ import { ActionEntity } from '../entity/action.entity';
6
7
 
7
8
  @Injectable()
8
9
  export class ActionService extends EntityServiceImpl {
@@ -10,6 +11,26 @@ export class ActionService extends EntityServiceImpl {
10
11
  super();
11
12
  }
12
13
 
14
+ async getEntityData(
15
+ entityType: string,
16
+ id: number,
17
+ loggedInUser,
18
+ ): Promise<any> {
19
+ const actionData = await super.getEntityData(entityType, id, loggedInUser);
20
+
21
+ if (!actionData) {
22
+ return null;
23
+ }
24
+
25
+ const template = await this.dataSource.query(
26
+ `SELECT template_code FROM cr_wf_action_template_mapping WHERE stg_act_mapping_id =
27
+ (SELECT id FROM cr_wf_stage_action_mapping WHERE action_id = ? AND entity_type = 'STGM')`,
28
+ [actionData.id],
29
+ );
30
+
31
+ return { ...actionData, template: template.map((t) => t.template_code) };
32
+ }
33
+
13
34
  async createEntity(
14
35
  entityData: BaseEntity,
15
36
  loggedInUser: UserData | null,
@@ -27,6 +48,7 @@ export class ActionService extends EntityServiceImpl {
27
48
  appcode,
28
49
  );
29
50
 
51
+ // stage mapping
30
52
  let stageActionMapping = {
31
53
  action_id: action.id,
32
54
  stage_id: actionData.stage_id,
@@ -44,20 +66,7 @@ export class ActionService extends EntityServiceImpl {
44
66
  const templates = actionData.template;
45
67
 
46
68
  for (let i = 0; i < templates.length; i++) {
47
- const templateId = templates[i];
48
-
49
- // Fetch the template code from `cr_wf_comm_template`
50
- const templateResult = await this.dataSource.query(
51
- `SELECT code FROM cr_wf_comm_template WHERE id = ?`,
52
- [templateId],
53
- );
54
-
55
- if (templateResult.length === 0) {
56
- console.warn(`Template not found for id: ${templateId}`);
57
- continue;
58
- }
59
-
60
- const templateCode = templateResult[0].code;
69
+ const templateCode = templates[i];
61
70
 
62
71
  // Create Action-Template Mapping
63
72
  const actionTemplateMapping = {
@@ -77,4 +86,66 @@ export class ActionService extends EntityServiceImpl {
77
86
 
78
87
  return actionData;
79
88
  }
89
+
90
+ async updateEntity(
91
+ entityData: BaseEntity,
92
+ loggedInUser: UserData,
93
+ ): Promise<any> {
94
+ console.log('entityData', entityData);
95
+
96
+ // Extract template from entityData, keep the rest for ActionEntity
97
+ const { template, stage_id, ...actionData } = entityData as ActionEntity & {
98
+ template?: number[];
99
+ stage_id?: string;
100
+ };
101
+
102
+ // Pass only actionData (without template) to super.updateEntity
103
+ let action = await super.updateEntity(actionData, loggedInUser);
104
+
105
+ if (!action) {
106
+ throw new Error('Action not found or could not be updated');
107
+ }
108
+
109
+ const stageMapID = await this.dataSource.query(
110
+ `SELECT id FROM cr_wf_stage_action_mapping WHERE action_id = ? AND entity_type = 'STGM'`,
111
+ [action.id],
112
+ );
113
+
114
+ // stage mapping
115
+ let stageActionMapping = {
116
+ action_id: action.id,
117
+ stage_id: stage_id,
118
+ entity_type: 'STGM',
119
+ id: stageMapID.length > 0 ? stageMapID[0].id : null,
120
+ } as any;
121
+
122
+ let stageActionMappingData = await super.updateEntity(
123
+ stageActionMapping,
124
+ loggedInUser,
125
+ );
126
+
127
+ // Handle template mapping (using the extracted template)
128
+ if (Array.isArray(template) && template.length > 0) {
129
+ for (let i = 0; i < template.length; i++) {
130
+ const templateCode = template[i];
131
+
132
+ // delete existing template mappings for this action
133
+ await this.dataSource.query(
134
+ `DELETE FROM cr_wf_action_template_mapping WHERE stg_act_mapping_id = ? AND template_code = ?`,
135
+ [stageActionMappingData.id, templateCode],
136
+ );
137
+
138
+ // Create Action-Template Mapping
139
+ const actionTemplateMapping = {
140
+ stg_act_mapping_id: stageActionMappingData.id,
141
+ template_code: templateCode,
142
+ entity_type: 'ATMP',
143
+ } as any;
144
+
145
+ await super.createEntity(actionTemplateMapping, loggedInUser);
146
+ }
147
+ }
148
+
149
+ return action; // Return the action entity instead of actionData
150
+ }
80
151
  }
@@ -1,5 +1,24 @@
1
1
  import { Injectable } from '@nestjs/common';
2
- import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
2
+ import { CommTemplateRepository } from '../repository/comm-template.repository';
3
3
 
4
4
  @Injectable()
5
- export class CommTemplateService extends EntityServiceImpl {}
5
+ export class CommTemplateService {
6
+ constructor(
7
+ private readonly commTemplateRepository: CommTemplateRepository,
8
+ ) {}
9
+
10
+ async getAllCommTemplate(entity_type: string, loggedInUser) {
11
+ const commTemplateData =
12
+ await this.commTemplateRepository.getAllCommTemplate(
13
+ entity_type,
14
+ loggedInUser,
15
+ );
16
+
17
+ const response = commTemplateData.map((item) => ({
18
+ label: item.name,
19
+ value: item.code,
20
+ }));
21
+
22
+ return response;
23
+ }
24
+ }