rez_core 2.1.145 → 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.
Files changed (90) hide show
  1. package/dist/module/layout_preference/controller/layout_preference.controller.js +2 -2
  2. package/dist/module/layout_preference/controller/layout_preference.controller.js.map +1 -1
  3. package/dist/module/layout_preference/entity/layout_preference.entity.d.ts +2 -0
  4. package/dist/module/layout_preference/entity/layout_preference.entity.js +13 -0
  5. package/dist/module/layout_preference/entity/layout_preference.entity.js.map +1 -1
  6. package/dist/module/layout_preference/repository/layout_preference.repository.d.ts +1 -1
  7. package/dist/module/layout_preference/repository/layout_preference.repository.js +4 -2
  8. package/dist/module/layout_preference/repository/layout_preference.repository.js.map +1 -1
  9. package/dist/module/layout_preference/service/layout_preference.service.d.ts +1 -1
  10. package/dist/module/layout_preference/service/layout_preference.service.js +10 -4
  11. package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
  12. package/dist/module/meta/controller/media.controller.d.ts +1 -1
  13. package/dist/module/meta/controller/media.controller.js +1 -1
  14. package/dist/module/meta/controller/media.controller.js.map +1 -1
  15. package/dist/module/workflow/controller/action-category.controller.d.ts +8 -0
  16. package/dist/module/workflow/controller/action-category.controller.js +45 -0
  17. package/dist/module/workflow/controller/action-category.controller.js.map +1 -0
  18. package/dist/module/workflow/controller/action.controller.d.ts +1 -1
  19. package/dist/module/workflow/controller/action.controller.js +3 -3
  20. package/dist/module/workflow/controller/action.controller.js.map +1 -1
  21. package/dist/module/workflow/controller/comm-template.controller.d.ts +2 -2
  22. package/dist/module/workflow/controller/comm-template.controller.js +4 -4
  23. package/dist/module/workflow/controller/comm-template.controller.js.map +1 -1
  24. package/dist/module/workflow/controller/workflow-meta.controller.d.ts +9 -0
  25. package/dist/module/workflow/controller/workflow-meta.controller.js +63 -0
  26. package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -0
  27. package/dist/module/workflow/controller/workflow.controller.d.ts +9 -1
  28. package/dist/module/workflow/controller/workflow.controller.js +17 -2
  29. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  30. package/dist/module/workflow/entity/action-category.entity.d.ts +1 -0
  31. package/dist/module/workflow/entity/action-category.entity.js +4 -0
  32. package/dist/module/workflow/entity/action-category.entity.js.map +1 -1
  33. package/dist/module/workflow/entity/action.entity.d.ts +1 -1
  34. package/dist/module/workflow/entity/action.entity.js +1 -1
  35. package/dist/module/workflow/entity/comm-template.entity.d.ts +5 -0
  36. package/dist/module/workflow/entity/comm-template.entity.js +21 -1
  37. package/dist/module/workflow/entity/comm-template.entity.js.map +1 -1
  38. package/dist/module/workflow/entity/stage-movement-data.entity.d.ts +2 -0
  39. package/dist/module/workflow/entity/stage-movement-data.entity.js +8 -0
  40. package/dist/module/workflow/entity/stage-movement-data.entity.js.map +1 -1
  41. package/dist/module/workflow/entity/template-attach-mapper.entity.d.ts +11 -0
  42. package/dist/module/workflow/entity/template-attach-mapper.entity.js +54 -0
  43. package/dist/module/workflow/entity/template-attach-mapper.entity.js.map +1 -0
  44. package/dist/module/workflow/repository/comm-template.repository.d.ts +8 -2
  45. package/dist/module/workflow/repository/comm-template.repository.js +37 -6
  46. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  47. package/dist/module/workflow/service/action-category.service.d.ts +5 -0
  48. package/dist/module/workflow/service/action-category.service.js +20 -1
  49. package/dist/module/workflow/service/action-category.service.js.map +1 -1
  50. package/dist/module/workflow/service/action.service.d.ts +1 -1
  51. package/dist/module/workflow/service/action.service.js +58 -10
  52. package/dist/module/workflow/service/action.service.js.map +1 -1
  53. package/dist/module/workflow/service/comm-template.service.d.ts +4 -1
  54. package/dist/module/workflow/service/comm-template.service.js +38 -1
  55. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  56. package/dist/module/workflow/service/populate-workflow.service.d.ts +21 -0
  57. package/dist/module/workflow/service/populate-workflow.service.js +124 -0
  58. package/dist/module/workflow/service/populate-workflow.service.js.map +1 -0
  59. package/dist/module/workflow/service/workflow-list-master.service.js +3 -3
  60. package/dist/module/workflow/service/workflow-meta.service.d.ts +9 -0
  61. package/dist/module/workflow/service/workflow-meta.service.js +81 -0
  62. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -0
  63. package/dist/module/workflow/workflow.module.js +41 -26
  64. package/dist/module/workflow/workflow.module.js.map +1 -1
  65. package/dist/tsconfig.build.tsbuildinfo +1 -1
  66. package/package.json +1 -1
  67. package/src/module/layout_preference/controller/layout_preference.controller.ts +4 -2
  68. package/src/module/layout_preference/entity/layout_preference.entity.ts +11 -0
  69. package/src/module/layout_preference/repository/layout_preference.repository.ts +6 -2
  70. package/src/module/layout_preference/service/layout_preference.service.ts +24 -6
  71. package/src/module/meta/controller/media.controller.ts +5 -7
  72. package/src/module/workflow/controller/action-category.controller.ts +35 -0
  73. package/src/module/workflow/controller/action.controller.ts +2 -2
  74. package/src/module/workflow/controller/comm-template.controller.ts +5 -4
  75. package/src/module/workflow/controller/workflow-meta.controller.ts +52 -0
  76. package/src/module/workflow/controller/workflow.controller.ts +14 -0
  77. package/src/module/workflow/entity/action-category.entity.ts +3 -0
  78. package/src/module/workflow/entity/action.entity.ts +1 -1
  79. package/src/module/workflow/entity/comm-template.entity.ts +18 -1
  80. package/src/module/workflow/entity/stage-movement-data.entity.ts +6 -0
  81. package/src/module/workflow/entity/template-attach-mapper.entity.ts +30 -0
  82. package/src/module/workflow/repository/comm-template.repository.ts +58 -5
  83. package/src/module/workflow/service/action-category.service.ts +23 -1
  84. package/src/module/workflow/service/action-template-mapping.service.ts +1 -1
  85. package/src/module/workflow/service/action.service.ts +86 -10
  86. package/src/module/workflow/service/comm-template.service.ts +54 -1
  87. package/src/module/workflow/service/populate-workflow.service.ts +189 -0
  88. package/src/module/workflow/service/workflow-list-master.service.ts +3 -3
  89. package/src/module/workflow/service/workflow-meta.service.ts +98 -0
  90. package/src/module/workflow/workflow.module.ts +41 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.145",
3
+ "version": "2.1.147",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -15,11 +15,13 @@ export class LayoutPreferenceController {
15
15
  @Query('entity_type') entity_type: string,
16
16
  @Req() req: Request & { user: any },
17
17
  ) {
18
- const userId = req.user.userData.id;
18
+ const userDat = req.user.userData;
19
19
 
20
20
  return this.layoutPreferenceService.getLayoutPreferenceByUserID(
21
- userId,
21
+ userDat.id,
22
22
  entity_type,
23
+ userDat.level_id,
24
+ userDat.level_type,
23
25
  );
24
26
  }
25
27
 
@@ -14,4 +14,15 @@ export class LayoutPreference extends BaseEntity {
14
14
 
15
15
  @Column({ nullable: true, type: 'json' })
16
16
  navigation_tabs_json: any;
17
+
18
+ @Column({
19
+ name: 'mapped_level_id',
20
+ type: 'varchar',
21
+ length: 100,
22
+ nullable: true,
23
+ })
24
+ mapped_level_id: string;
25
+
26
+ @Column({ name: 'mapped_level_type', type: 'varchar', nullable: true })
27
+ mapped_level_type: string;
17
28
  }
@@ -11,13 +11,17 @@ export class LayoutPreferenceRepository {
11
11
  ) {}
12
12
 
13
13
  async findByEntityUserId(
14
- entity_type: string,
14
+ mapped_entity_type: string,
15
+ mapped_level_id: string,
16
+ mapped_level_type: string,
15
17
  userId: number,
16
18
  ): Promise<LayoutPreference | null> {
17
19
  return this.layoutPreferenceRepo.findOne({
18
20
  where: {
19
21
  user_id: userId.toString(),
20
- mapped_entity_type: entity_type,
22
+ mapped_entity_type: mapped_entity_type,
23
+ mapped_level_id: mapped_level_id,
24
+ mapped_level_type: mapped_level_type,
21
25
  },
22
26
  });
23
27
  }
@@ -27,6 +27,8 @@ export class LayoutPreferenceService extends EntityServiceImpl {
27
27
  const existingLayoutPreference =
28
28
  await this.layoutPreferenceRepository.findByEntityUserId(
29
29
  mapped_entity_type,
30
+ loggedInUser.level_id,
31
+ loggedInUser.level_type,
30
32
  userId,
31
33
  );
32
34
 
@@ -38,16 +40,31 @@ export class LayoutPreferenceService extends EntityServiceImpl {
38
40
  }
39
41
 
40
42
  return await super.createEntity(
41
- { ...entityData, user_id: userId } as any,
43
+ {
44
+ ...entityData,
45
+ user_id: userId,
46
+ mapped_level_id: loggedInUser.level_id,
47
+ mapped_level_type: loggedInUser.level_type,
48
+ } as any,
42
49
  loggedInUser,
43
50
  );
44
51
  }
45
52
 
46
- async getLayoutPreferenceByUserID(user_id, mapped_entity_type) {
47
- return await this.layoutPreferenceRepository.findByEntityUserId(
48
- mapped_entity_type,
49
- user_id,
50
- );
53
+ async getLayoutPreferenceByUserID(
54
+ user_id,
55
+ mapped_entity_type,
56
+ mapped_level_id,
57
+ mapped_level_type,
58
+ ) {
59
+ const layoutPreference =
60
+ await this.layoutPreferenceRepository.findByEntityUserId(
61
+ mapped_entity_type,
62
+ mapped_level_id,
63
+ mapped_level_type,
64
+ user_id,
65
+ );
66
+
67
+ return layoutPreference;
51
68
  }
52
69
 
53
70
  async getColumnValue(
@@ -65,6 +82,7 @@ export class LayoutPreferenceService extends EntityServiceImpl {
65
82
  );
66
83
 
67
84
  const tableName = getTableMeta?.data_source;
85
+
68
86
  if (!tableName) {
69
87
  throw new Error('Invalid or missing table name in metadata');
70
88
  }
@@ -1,19 +1,17 @@
1
1
  import {
2
2
  Body,
3
3
  Controller,
4
+ Get,
4
5
  HttpStatus,
6
+ Param,
5
7
  Post,
8
+ Req,
6
9
  Res,
7
- Get,
8
- Param,
9
10
  UseGuards,
10
- Req,
11
11
  } from '@nestjs/common';
12
- import { MediaDataService } from '../service/media-data.service';
12
+ import { Response } from 'express';
13
13
  import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
14
- import e, { Response } from 'express';
15
- import { ENTITYTYPE_MEDIA } from 'src/constant/global.constant';
16
- import { MediaData } from '../entity/media-data.entity';
14
+ import { MediaDataService } from '../service/media-data.service';
17
15
 
18
16
  @Controller('media')
19
17
  @UseGuards(JwtAuthGuard)
@@ -0,0 +1,35 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ HttpCode,
5
+ HttpStatus,
6
+ Inject,
7
+ Post,
8
+ Req,
9
+ UseGuards,
10
+ } from '@nestjs/common';
11
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
12
+ import { ActionCategoryService } from '../service/action-category.service';
13
+
14
+ @Controller('/actionCategory')
15
+ @UseGuards(JwtAuthGuard)
16
+ export class ActionCategoryController {
17
+ constructor(
18
+ @Inject('ActionCategoryService')
19
+ private readonly actionCategoryService: ActionCategoryService,
20
+ ) {}
21
+
22
+ @Post('/getActionsCategory')
23
+ @HttpCode(HttpStatus.OK)
24
+ async getActionsCat(
25
+ @Req() req: Request & { user: any },
26
+ @Body('entity_type') entity_type: string,
27
+ ) {
28
+ const loggedInUser = req.user.userData;
29
+ const result = this.actionCategoryService.getActionsCat(
30
+ loggedInUser,
31
+ entity_type,
32
+ );
33
+ return result;
34
+ }
35
+ }
@@ -46,10 +46,10 @@ export class ActionController {
46
46
  @HttpCode(HttpStatus.OK)
47
47
  async getActions(
48
48
  @Req() req: Request & { user: any },
49
- @Body('workflow_id') workflow_id: number,
49
+ @Body('stage_id') stage_id: number,
50
50
  ) {
51
51
  const loggedInUser = req.user.userData;
52
- const result = this.actionService.getActions(loggedInUser, workflow_id);
52
+ const result = this.actionService.getActions(loggedInUser, stage_id);
53
53
  return result;
54
54
  }
55
55
  }
@@ -1,8 +1,9 @@
1
1
  import {
2
+ Body,
2
3
  Controller,
3
- Get,
4
4
  HttpCode,
5
5
  HttpStatus,
6
+ Post,
6
7
  Query,
7
8
  Req,
8
9
  UseGuards,
@@ -15,15 +16,15 @@ import { CommTemplateService } from '../service/comm-template.service';
15
16
  export class CommTemplateController {
16
17
  constructor(private readonly commTemplateService: CommTemplateService) {}
17
18
 
18
- @Get('/get-comm-template')
19
+ @Post('/getTemplates')
19
20
  @HttpCode(HttpStatus.OK)
20
21
  async getTemplate(
21
22
  @Req() req: Request & { user: any },
22
- @Query('entity_type') entityType?: string,
23
+ @Body('entity_type') entity_type: string,
23
24
  ) {
24
25
  const loggedInUser = req.user.userData;
25
26
  const result = this.commTemplateService.getAllCommTemplate(
26
- entityType || '',
27
+ entity_type || '',
27
28
  loggedInUser,
28
29
  );
29
30
  return result;
@@ -0,0 +1,52 @@
1
+ import { Controller, Get, Query, Post, Body } from '@nestjs/common';
2
+ import { WorkflowMetaService } from '../service/workflow-meta.service';
3
+ import { StageMovementData } from '../entity/stage-movement-data.entity';
4
+
5
+ @Controller('workflow-meta')
6
+ export class WorkflowMetaController {
7
+ constructor(private readonly workflowMetaService: WorkflowMetaService) {}
8
+
9
+ /**
10
+ * GET /meta/current-stage?entityType=...&entityId=...
11
+ */
12
+ @Get('current-stage')
13
+ async getCurrentStage(
14
+ @Query('entityType') mapped_entity_type: string,
15
+ @Query('entityId') mapped_entity_id: number,
16
+ ): Promise<StageMovementData | null> {
17
+ return this.workflowMetaService.getCurrentStage(mapped_entity_type, Number(mapped_entity_id));
18
+ }
19
+
20
+ /**
21
+ * GET /meta/next-stage?entityType=...&entityId=...
22
+ */
23
+ @Get('next-stage')
24
+ async getNextStage(
25
+ @Query('entityType') mapped_entity_type: string,
26
+ @Query('entityId') mapped_entity_id: number,
27
+ ): Promise<number | null> {
28
+ const current = await this.workflowMetaService.getCurrentStage(mapped_entity_type, Number(mapped_entity_id));
29
+ return current ? this.workflowMetaService.getNextStage(current) : null;
30
+ }
31
+
32
+ /**
33
+ * POST /meta/move-next-stage
34
+ * {
35
+ * "entityType": "lead",
36
+ * "entityId": 101,
37
+ * "currentUserId": 5
38
+ * }
39
+ */
40
+ @Post('move-next-stage')
41
+ async moveToNextStage(
42
+ @Body('entityType') mapped_entity_type: string,
43
+ @Body('entityId') mapped_entity_id: number,
44
+ @Body('currentUserId') current_user_id: number,
45
+ ): Promise<string> {
46
+ return this.workflowMetaService.moveToNextStage(
47
+ mapped_entity_type,
48
+ Number(mapped_entity_id),
49
+ current_user_id,
50
+ );
51
+ }
52
+ }
@@ -14,6 +14,7 @@ import {
14
14
  } from '@nestjs/common';
15
15
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
16
16
  import { WorkflowService } from '../service/workflow.service';
17
+ import { PopulateWorkflowService } from '../service/populate-workflow.service';
17
18
 
18
19
  @Controller('/workflow')
19
20
  @UseGuards(JwtAuthGuard)
@@ -21,6 +22,7 @@ export class WorkflowController {
21
22
  constructor(
22
23
  @Inject('WorkflowService')
23
24
  private readonly workflowService: WorkflowService,
25
+ private readonly populateWorkflowService: PopulateWorkflowService,
24
26
  ) {}
25
27
 
26
28
  @Post('/getAllWorkflows')
@@ -50,4 +52,16 @@ export class WorkflowController {
50
52
  const loggedInUser = req.user?.userData;
51
53
  return this.workflowService.updateSequence(body, loggedInUser);
52
54
  }
55
+
56
+ @Post('/populateWorkflow')
57
+ async populateWorkflow(
58
+ @Body() body: any,
59
+ @Req() req: Request & { user: any },
60
+ ) {
61
+ const loggedInUser = req.user?.userData;
62
+ return this.populateWorkflowService.populateWorkflowData(
63
+ body.organization_id,
64
+ loggedInUser,
65
+ );
66
+ }
53
67
  }
@@ -14,4 +14,7 @@ export class ActionCategory extends BaseEntity {
14
14
 
15
15
  @Column({ type: 'varchar', nullable: true })
16
16
  modalName: string;
17
+
18
+ @Column({ type: 'varchar', nullable: true })
19
+ mapped_entity_type: string;
17
20
  }
@@ -19,7 +19,7 @@ export class ActionEntity extends BaseEntity {
19
19
  action_requirement: string;
20
20
 
21
21
  @Column({ type: 'varchar', nullable: true })
22
- template: string;
22
+ sequence: string;
23
23
 
24
24
  @Column({ type: 'varchar', nullable: true })
25
25
  reason_code: string;
@@ -9,6 +9,23 @@ export class CommTemplate extends BaseEntity {
9
9
  this.entity_type = COMM_TEMPLATE;
10
10
  }
11
11
 
12
- @Column({ type: 'varchar', nullable: true })
12
+ @Column({ nullable: true })
13
13
  mode: string;
14
+
15
+ @Column({ type: 'varchar', nullable: true })
16
+ mapped_entity_type: string;
17
+
18
+ @Column({ nullable: true })
19
+ subject: string;
20
+
21
+ @Column({ nullable: true })
22
+ format_type: string;
23
+
24
+ // if format_type is 'richtext', this field will be used
25
+ @Column({ type: 'longtext', nullable: true })
26
+ rich_text: string;
27
+
28
+ // if format_type is 'markup', this field will be used
29
+ @Column({ nullable: true })
30
+ markup_id: number;
14
31
  }
@@ -23,4 +23,10 @@ export class StageMovementData extends BaseEntity {
23
23
 
24
24
  @Column({ type: 'varchar', nullable: true })
25
25
  is_current: string;
26
+
27
+ @Column({ type: 'varchar', nullable: true })
28
+ mapped_entity_type: string;
29
+
30
+ @Column({ type: 'int', nullable: true })
31
+ mapped_entity_id: number;
26
32
  }
@@ -0,0 +1,30 @@
1
+ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
2
+
3
+ @Entity({ name: 'cr_wf_tem_attach_mapper' })
4
+ export class TemplateAttach {
5
+ constructor() {}
6
+
7
+ @PrimaryGeneratedColumn()
8
+ id: number;
9
+
10
+ @Column({})
11
+ entity_type: string;
12
+
13
+ @Column({ nullable: true })
14
+ template_id: number;
15
+
16
+ @Column({ nullable: true })
17
+ media_id: number;
18
+
19
+ @Column({ nullable: true })
20
+ organization_id: number;
21
+
22
+ @Column({ nullable: true })
23
+ appcode: string;
24
+
25
+ @Column({ nullable: true })
26
+ level_id: string;
27
+
28
+ @Column({ nullable: true })
29
+ level_type: string;
30
+ }
@@ -3,32 +3,56 @@ import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { Workflow } from '../entity/workflow.entity';
4
4
  import { Repository } from 'typeorm';
5
5
  import { CommTemplate } from '../entity/comm-template.entity';
6
+ import { TemplateAttach } from '../entity/template-attach-mapper.entity';
7
+ import { MediaDataService } from 'src/module/meta/service/media-data.service';
6
8
 
7
9
  @Injectable()
8
10
  export class CommTemplateRepository {
9
11
  constructor(
10
12
  @InjectRepository(CommTemplate)
11
13
  private readonly commTemplateRepository: Repository<CommTemplate>,
14
+ @InjectRepository(TemplateAttach)
15
+ private readonly templateAttachEntity: Repository<TemplateAttach>,
16
+ private readonly mediaDataService: MediaDataService,
12
17
  ) {}
13
18
 
14
19
  async getAllCommTemplate(entity_type: string, loggedInUser) {
20
+ const { organization_id } = loggedInUser;
15
21
  return this.commTemplateRepository.find({
16
22
  select: ['name', 'code'],
17
23
  where: {
18
- entity_type: entity_type,
24
+ mapped_entity_type: entity_type,
25
+ organization_id: organization_id,
19
26
  },
20
27
  });
21
28
  }
22
29
 
30
+ async save(commTemplate: any): Promise<any> {
31
+ // // delete existing mapper
32
+ // for (const attachment of commTemplate || []) {
33
+ // await this.templateAttachEntity.delete({
34
+ // entity_type: attachment.entity_type,
35
+ // template_id: attachment.template_id,
36
+ // });
37
+ // }
38
+
39
+ return this.templateAttachEntity.save(commTemplate);
40
+ }
41
+
42
+ async delete(id: any): Promise<any> {
43
+ // delete existing mapper
44
+ return await this.templateAttachEntity.delete(id);
45
+ }
46
+
23
47
  async getTemplateByCode(
24
48
  entity_type: string,
25
49
  code: string,
26
50
  loggedInUser,
27
- ): Promise<CommTemplate | null> {
51
+ ): Promise<any | null> {
28
52
  const template = await this.commTemplateRepository.findOne({
29
53
  where: {
30
- entity_type: entity_type,
31
- code: code,
54
+ entity_type,
55
+ code,
32
56
  },
33
57
  });
34
58
 
@@ -36,6 +60,35 @@ export class CommTemplateRepository {
36
60
  throw new NotFoundException(`Template with code ${code} not found`);
37
61
  }
38
62
 
39
- return template;
63
+ if (template.format_type === 'markup') {
64
+ const media = await this.mediaDataService.getMediaDownloadUrl(
65
+ template.markup_id,
66
+ loggedInUser,
67
+ );
68
+
69
+ console.log(media);
70
+ }
71
+
72
+ if (template.format_type === 'richtext') {
73
+ return template;
74
+ }
75
+
76
+ // Get only attachment IDs
77
+ const attachments = await this.templateAttachEntity.find({
78
+ select: ['media_id'],
79
+ where: {
80
+ entity_type: entity_type,
81
+ template_id: template.id,
82
+ },
83
+ });
84
+
85
+ const media = await this.mediaDataService.getMediaDownloadUrl(
86
+ 1,
87
+ loggedInUser,
88
+ );
89
+
90
+ console.log(media);
91
+
92
+ return { ...template, attachments: attachments.map((att) => att.media_id) };
40
93
  }
41
94
  }
@@ -1,5 +1,27 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
+ import { UserData } from 'src/module/user/entity/user.entity';
4
+ import { DataSource } from 'typeorm';
3
5
 
4
6
  @Injectable()
5
- export class ActionCategoryService extends EntityServiceImpl {}
7
+ export class ActionCategoryService extends EntityServiceImpl {
8
+ constructor(private readonly dataSource: DataSource) {
9
+ super();
10
+ }
11
+
12
+ async getActionsCat(loggedInUser: UserData, entity_type: string) {
13
+ const { organization_id } = loggedInUser;
14
+
15
+ const result = await this.dataSource.query(
16
+ `
17
+ SELECT id, name
18
+ FROM cr_wf_action_category
19
+ WHERE mapped_entity_type = ?
20
+ AND organization_id = ?
21
+ `,
22
+ [entity_type, organization_id],
23
+ );
24
+
25
+ return result;
26
+ }
27
+ }
@@ -36,7 +36,7 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
36
36
  [mode],
37
37
  );
38
38
 
39
- if (!listMasterItemData?.length) return []; // 🛑 No mode found
39
+ if (!listMasterItemData?.length) return [];
40
40
 
41
41
  const templateCodes = templates.map((t) => t.template_code);
42
42
  if (!templateCodes.length) return [];
@@ -210,33 +210,109 @@ export class ActionService extends EntityServiceImpl {
210
210
  }));
211
211
  }
212
212
 
213
- async getActions(loggedInUser: UserData, workflow_id: number) {
213
+ async getActions(loggedInUser: UserData, stage_id: number) {
214
214
  const { organization_id } = loggedInUser;
215
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
216
278
  const result = await this.dataSource.query(
217
279
  `
218
280
  SELECT
281
+ a.id,
219
282
  a.name AS action_name,
220
283
  ac.name AS action_category,
221
- ar.name AS action_requirement,
222
- 'Email Template' AS template
223
-
284
+ ar.name AS action_requirement
224
285
  FROM cr_wf_action a
225
-
226
286
  LEFT JOIN cr_wf_action_category ac
227
287
  ON ac.id = a.action_cat_id
228
-
229
288
  LEFT JOIN cr_list_master_items ar
230
289
  ON ar.id = a.action_requirement
231
290
  AND ar.listtype = 'ACRQ'
232
291
  AND ar.organization_id = ?
233
-
234
292
  WHERE a.organization_id = ?
235
- AND a.workflow_id = ?
293
+ AND a.id IN (?)
236
294
  `,
237
- [organization_id, organization_id, workflow_id],
295
+ [organization_id, organization_id, actionIds],
238
296
  );
239
297
 
240
- return result;
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;
241
317
  }
242
318
  }