rez_core 2.2.20 → 2.2.21

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": "2.2.20",
3
+ "version": "2.2.21",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -54,15 +54,23 @@ export class OtpController {
54
54
  return { message: 'OTP verified successfully!', success: true };
55
55
  }
56
56
 
57
- @Get('send-mail')
57
+ @Post('send-mail')
58
58
  @HttpCode(HttpStatus.OK)
59
- async sendMail(@Query('email') email: string) {
59
+ async sendMail(
60
+ @Body()
61
+ body: {
62
+ to: string;
63
+ subject: string;
64
+ templateCode: number;
65
+ payload: any;
66
+ },
67
+ ) {
60
68
  // return await this.emailService.sendEmail(email, 'Harry', '123456');
61
69
  return await this.emailService.sendEmailWithDynamicTemplate(
62
- email,
63
- 'Sample OTP',
64
- '<div style="font-family: Arial, sans-serif; padding: 20px; background-color: #f7f9fc; color: #333;"> <div style="max-width: 600px; margin: auto; background-color: #ffffff; padding: 30px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);"> <h2 style="color: #2c3e50;">Hello {{name}},</h2> <p style="font-size: 16px; line-height: 1.6;"> We received a request to verify your email address using a one-time password (OTP). </p> <p style="font-size: 16px; line-height: 1.6;"> Please use the following OTP to complete your action: </p> <div style="text-align: center; margin: 20px 0;"> <span style="font-size: 24px; font-weight: bold; color: #2e86de;">{{otp}}</span> </div> <p style="font-size: 16px; line-height: 1.6;"> This OTP is valid for the next 10 minutes. If you did not request this, please ignore this email. </p> <p style="font-size: 16px; line-height: 1.6;"> Regards,<br/> <strong>Your Company Team</strong> </p> <hr style="margin-top: 30px;"/> <p style="font-size: 12px; color: #999;"> This is an automated message, please do not reply to this email. </p> </div> </div>',
65
- { name: 'Harsh', otp: '123456' },
70
+ body.to,
71
+ body.subject,
72
+ body.templateCode,
73
+ body.payload,
66
74
  );
67
75
  }
68
76
  }
@@ -1,10 +1,14 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { MailerService } from '@nestjs-modules/mailer';
3
3
  import * as Handlebars from 'handlebars';
4
+ import { DataSource } from 'typeorm';
4
5
 
5
6
  @Injectable()
6
7
  export class EmailService {
7
- constructor(private readonly mailerService: MailerService) {}
8
+ constructor(
9
+ private readonly mailerService: MailerService,
10
+ private readonly datasource: DataSource,
11
+ ) {}
8
12
 
9
13
  async sendEmail(email, name: string, otp: string) {
10
14
  this.mailerService
@@ -24,9 +28,22 @@ export class EmailService {
24
28
  async sendEmailWithDynamicTemplate(
25
29
  email: string,
26
30
  subject: string,
27
- templateString: string,
31
+ templateCode: number,
28
32
  context?: any,
29
33
  ) {
34
+ // retrieve the rich_text from the database table cr_wf_comm_template for the given templateCode
35
+
36
+ const template = await this.datasource
37
+ .getRepository('cr_wf_comm_template')
38
+ .findOne({ where: { code: templateCode } });
39
+
40
+ if (!template) {
41
+ throw new Error(`Template with code ${templateCode} not found`);
42
+ }
43
+
44
+ // Compile the template string with Handlebars
45
+ const templateString = template.rich_text || '';
46
+
30
47
  const compiled = Handlebars.compile(templateString);
31
48
  const htmlContent = compiled(context);
32
49
 
@@ -141,7 +141,7 @@ export class ActionService extends EntityServiceImpl {
141
141
 
142
142
  // delete existing template mappings for this action
143
143
  await this.dataSource.query(
144
- `DELETE FROM cr_wf_action_template_mapping WHERE stg_act_mapping_id = ?`,
144
+ `DELETE FROM cr_wf_action_resources_mapping WHERE stg_act_mapping_id = ? AND type = 'template'`,
145
145
  [stageActionMappingData.id],
146
146
  );
147
147
 
@@ -162,6 +162,11 @@ export class ActionService extends EntityServiceImpl {
162
162
  }
163
163
  }
164
164
 
165
+ await this.dataSource.query(
166
+ `DELETE FROM cr_wf_action_resources_mapping WHERE stg_act_mapping_id = ? AND type = 'form'`,
167
+ [stageActionMappingData.id],
168
+ );
169
+
165
170
  if (form) {
166
171
  const resourceMapping = {
167
172
  stg_act_mapping_id: stageActionMappingData.id,