rez_core 3.1.187 → 3.1.188

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "3.1.187",
3
+ "version": "3.1.188",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -14,7 +14,8 @@ import { CommTemplateService } from '../service/comm-template.service';
14
14
  @Controller('/templates')
15
15
  @UseGuards(JwtAuthGuard)
16
16
  export class CommTemplateController {
17
- constructor(private readonly commTemplateService: CommTemplateService) {}
17
+ constructor(private readonly commTemplateService: CommTemplateService) {
18
+ }
18
19
 
19
20
  @Post('/getTemplates')
20
21
  @HttpCode(HttpStatus.OK)
@@ -31,4 +32,10 @@ export class CommTemplateController {
31
32
  );
32
33
  return result;
33
34
  }
35
+
36
+ @Post('/resolve-message')
37
+ @HttpCode(HttpStatus.OK)
38
+ async resolveMessage(@Body() payload: any) {
39
+ return await this.commTemplateService.getResolvedTemplateMsg(payload);
40
+ }
34
41
  }
@@ -139,4 +139,11 @@ export class CommTemplateRepository {
139
139
  attachments: attachmentsMedia, // [] or array of media JSONs
140
140
  };
141
141
  }
142
+
143
+ async findByCodeAndLevelIdAndLevelTypeAndAppCode(code: string, level_id: string,
144
+ level_type: string, appcode: string) {
145
+ return await this.commTemplateRepository.findOne({
146
+ where: {code, level_id, level_type, appcode}
147
+ })
148
+ }
142
149
  }
@@ -1,12 +1,18 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { BadRequestException, Inject, Injectable } from '@nestjs/common';
2
2
  import { CommTemplateRepository } from '../repository/comm-template.repository';
3
3
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
4
- import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
5
4
  import { UserData } from 'src/module/user/entity/user.entity';
5
+ import axios from 'axios';
6
+ import { MediaDataService } from '../../meta/service/media-data.service';
7
+ import { FieldMapperService } from '../../mapper/service/field-mapper.service';
6
8
 
7
9
  @Injectable()
8
10
  export class CommTemplateService extends EntityServiceImpl {
9
- constructor(private readonly commTemplateRepository: CommTemplateRepository) {
11
+ constructor(private readonly commTemplateRepository: CommTemplateRepository,
12
+ private readonly mediaService: MediaDataService,
13
+ @Inject('FieldMapperService')
14
+ private readonly fieldMapperService: FieldMapperService,
15
+ ) {
10
16
  super();
11
17
  }
12
18
 
@@ -118,4 +124,53 @@ export class CommTemplateService extends EntityServiceImpl {
118
124
 
119
125
  return response;
120
126
  }
127
+
128
+ async getResolvedTemplateMsg(payload: any) {
129
+ let commTemplate = await this.commTemplateRepository.findByCodeAndLevelIdAndLevelTypeAndAppCode(
130
+ payload.template_code,
131
+ payload.level_type,
132
+ payload.level_id,
133
+ payload.appcode,
134
+ );
135
+
136
+ let variables;
137
+ if (commTemplate && ! commTemplate.template_id) {
138
+
139
+ if (commTemplate.mapper_id) {
140
+ variables = await this.fieldMapperService.resolveData(
141
+ commTemplate.mapper_id,
142
+ 'LOOKUP',
143
+ payload.entity_type,
144
+ payload.entity_id,
145
+ {} as any,
146
+ );
147
+ }
148
+
149
+ if (!commTemplate.template_id) {
150
+ let richText = commTemplate.rich_text;
151
+
152
+ if (!richText) {
153
+ if (commTemplate.markup_id) {
154
+ let url = await this.mediaService.getMediaDownloadUrl(commTemplate.markup_id, {}, 60000);
155
+ if (url) {
156
+ let response = await axios.get(url.signedUrl, { responseType: 'text' });
157
+ richText = response.data;
158
+ }
159
+ }
160
+ }
161
+
162
+ richText = richText.replace(/\{\{(\w+)\}\}/g, (match, key) => {
163
+ const value = variables[key];
164
+ return value !== undefined ? String(value) : match;
165
+ });
166
+
167
+ return {
168
+ rich_text: richText,
169
+ subject: commTemplate.subject,
170
+ };
171
+ }
172
+ } else {
173
+ throw new BadRequestException("Editing is disabled for external templates");
174
+ }
175
+ }
121
176
  }
@@ -61,6 +61,7 @@ import { ActivityLogService } from './service/activity-log.service';
61
61
  import { ActivityLogRepository } from './repository/activity-log.repository';
62
62
  import { ActivityLogController } from './controller/activity-log.controller';
63
63
  import { NotificationModule } from '../notification/notification.module';
64
+ import { MapperModule } from '../mapper/mapper.module';
64
65
 
65
66
  @Module({
66
67
  imports: [
@@ -85,6 +86,7 @@ import { NotificationModule } from '../notification/notification.module';
85
86
  EntityModule,
86
87
  ListMasterModule,
87
88
  NotificationModule,
89
+ MapperModule,
88
90
  ],
89
91
  providers: [
90
92
  { provide: 'ActionCategoryService', useClass: ActionCategoryService },