rez_core 2.1.144 → 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 (110) 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/layout_preference/controller/layout_preference.controller.js +2 -2
  7. package/dist/module/layout_preference/controller/layout_preference.controller.js.map +1 -1
  8. package/dist/module/layout_preference/entity/layout_preference.entity.d.ts +2 -0
  9. package/dist/module/layout_preference/entity/layout_preference.entity.js +13 -0
  10. package/dist/module/layout_preference/entity/layout_preference.entity.js.map +1 -1
  11. package/dist/module/layout_preference/repository/layout_preference.repository.d.ts +1 -1
  12. package/dist/module/layout_preference/repository/layout_preference.repository.js +4 -2
  13. package/dist/module/layout_preference/repository/layout_preference.repository.js.map +1 -1
  14. package/dist/module/layout_preference/service/layout_preference.service.d.ts +1 -1
  15. package/dist/module/layout_preference/service/layout_preference.service.js +10 -4
  16. package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
  17. package/dist/module/meta/controller/media.controller.d.ts +1 -1
  18. package/dist/module/meta/controller/media.controller.js +1 -1
  19. package/dist/module/meta/controller/media.controller.js.map +1 -1
  20. package/dist/module/workflow/controller/action-category.controller.d.ts +8 -0
  21. package/dist/module/workflow/controller/action-category.controller.js +45 -0
  22. package/dist/module/workflow/controller/action-category.controller.js.map +1 -0
  23. package/dist/module/workflow/controller/action.controller.d.ts +3 -0
  24. package/dist/module/workflow/controller/action.controller.js +14 -0
  25. package/dist/module/workflow/controller/action.controller.js.map +1 -1
  26. package/dist/module/workflow/controller/comm-template.controller.d.ts +2 -2
  27. package/dist/module/workflow/controller/comm-template.controller.js +4 -4
  28. package/dist/module/workflow/controller/comm-template.controller.js.map +1 -1
  29. package/dist/module/workflow/controller/entity-modification.controller.d.ts +8 -0
  30. package/dist/module/workflow/controller/entity-modification.controller.js +44 -0
  31. package/dist/module/workflow/controller/entity-modification.controller.js.map +1 -0
  32. package/dist/module/workflow/controller/workflow-meta.controller.d.ts +9 -0
  33. package/dist/module/workflow/controller/workflow-meta.controller.js +63 -0
  34. package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -0
  35. package/dist/module/workflow/controller/workflow.controller.d.ts +9 -1
  36. package/dist/module/workflow/controller/workflow.controller.js +17 -2
  37. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  38. package/dist/module/workflow/entity/action-category.entity.d.ts +1 -0
  39. package/dist/module/workflow/entity/action-category.entity.js +4 -0
  40. package/dist/module/workflow/entity/action-category.entity.js.map +1 -1
  41. package/dist/module/workflow/entity/action.entity.d.ts +1 -0
  42. package/dist/module/workflow/entity/action.entity.js +4 -0
  43. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  44. package/dist/module/workflow/entity/comm-template.entity.d.ts +5 -0
  45. package/dist/module/workflow/entity/comm-template.entity.js +21 -1
  46. package/dist/module/workflow/entity/comm-template.entity.js.map +1 -1
  47. package/dist/module/workflow/entity/entity-modification.entity.d.ts +13 -0
  48. package/dist/module/workflow/entity/entity-modification.entity.js +63 -0
  49. package/dist/module/workflow/entity/entity-modification.entity.js.map +1 -0
  50. package/dist/module/workflow/entity/stage-movement-data.entity.d.ts +2 -0
  51. package/dist/module/workflow/entity/stage-movement-data.entity.js +8 -0
  52. package/dist/module/workflow/entity/stage-movement-data.entity.js.map +1 -1
  53. package/dist/module/workflow/entity/template-attach-mapper.entity.d.ts +11 -0
  54. package/dist/module/workflow/entity/template-attach-mapper.entity.js +54 -0
  55. package/dist/module/workflow/entity/template-attach-mapper.entity.js.map +1 -0
  56. package/dist/module/workflow/repository/comm-template.repository.d.ts +8 -2
  57. package/dist/module/workflow/repository/comm-template.repository.js +37 -6
  58. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  59. package/dist/module/workflow/service/action-category.service.d.ts +5 -0
  60. package/dist/module/workflow/service/action-category.service.js +20 -1
  61. package/dist/module/workflow/service/action-category.service.js.map +1 -1
  62. package/dist/module/workflow/service/action.service.d.ts +1 -0
  63. package/dist/module/workflow/service/action.service.js +72 -0
  64. package/dist/module/workflow/service/action.service.js.map +1 -1
  65. package/dist/module/workflow/service/comm-template.service.d.ts +4 -1
  66. package/dist/module/workflow/service/comm-template.service.js +38 -1
  67. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  68. package/dist/module/workflow/service/entity-modification.service.d.ts +8 -0
  69. package/dist/module/workflow/service/entity-modification.service.js +52 -0
  70. package/dist/module/workflow/service/entity-modification.service.js.map +1 -0
  71. package/dist/module/workflow/service/populate-workflow.service.d.ts +21 -0
  72. package/dist/module/workflow/service/populate-workflow.service.js +124 -0
  73. package/dist/module/workflow/service/populate-workflow.service.js.map +1 -0
  74. package/dist/module/workflow/service/workflow-list-master.service.js +3 -3
  75. package/dist/module/workflow/service/workflow-meta.service.d.ts +9 -0
  76. package/dist/module/workflow/service/workflow-meta.service.js +81 -0
  77. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -0
  78. package/dist/module/workflow/workflow.module.js +48 -23
  79. package/dist/module/workflow/workflow.module.js.map +1 -1
  80. package/dist/tsconfig.build.tsbuildinfo +1 -1
  81. package/package.json +1 -1
  82. package/src/constant/global.constant.ts +2 -0
  83. package/src/module/enterprise/repository/school.repository.ts +23 -2
  84. package/src/module/layout_preference/controller/layout_preference.controller.ts +4 -2
  85. package/src/module/layout_preference/entity/layout_preference.entity.ts +11 -0
  86. package/src/module/layout_preference/repository/layout_preference.repository.ts +6 -2
  87. package/src/module/layout_preference/service/layout_preference.service.ts +24 -6
  88. package/src/module/meta/controller/media.controller.ts +5 -7
  89. package/src/module/workflow/controller/action-category.controller.ts +35 -0
  90. package/src/module/workflow/controller/action.controller.ts +11 -0
  91. package/src/module/workflow/controller/comm-template.controller.ts +5 -4
  92. package/src/module/workflow/controller/entity-modification.controller.ts +35 -0
  93. package/src/module/workflow/controller/workflow-meta.controller.ts +52 -0
  94. package/src/module/workflow/controller/workflow.controller.ts +14 -0
  95. package/src/module/workflow/entity/action-category.entity.ts +3 -0
  96. package/src/module/workflow/entity/action.entity.ts +3 -0
  97. package/src/module/workflow/entity/comm-template.entity.ts +18 -1
  98. package/src/module/workflow/entity/entity-modification.entity.ts +38 -0
  99. package/src/module/workflow/entity/stage-movement-data.entity.ts +6 -0
  100. package/src/module/workflow/entity/template-attach-mapper.entity.ts +30 -0
  101. package/src/module/workflow/repository/comm-template.repository.ts +58 -5
  102. package/src/module/workflow/service/action-category.service.ts +23 -1
  103. package/src/module/workflow/service/action-template-mapping.service.ts +1 -1
  104. package/src/module/workflow/service/action.service.ts +106 -0
  105. package/src/module/workflow/service/comm-template.service.ts +54 -1
  106. package/src/module/workflow/service/entity-modification.service.ts +67 -0
  107. package/src/module/workflow/service/populate-workflow.service.ts +189 -0
  108. package/src/module/workflow/service/workflow-list-master.service.ts +3 -3
  109. package/src/module/workflow/service/workflow-meta.service.ts +98 -0
  110. package/src/module/workflow/workflow.module.ts +48 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.144",
3
+ "version": "2.1.147",
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',
@@ -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
+ }
@@ -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('stage_id') stage_id: number,
50
+ ) {
51
+ const loggedInUser = req.user.userData;
52
+ const result = this.actionService.getActions(loggedInUser, stage_id);
53
+ return result;
54
+ }
44
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,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
+ }
@@ -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
  }
@@ -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
+ sequence: string;
23
+
21
24
  @Column({ type: 'varchar', nullable: true })
22
25
  reason_code: string;
23
26
 
@@ -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
  }
@@ -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
+ }
@@ -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 [];