rez_core 2.2.20 → 2.2.22

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 (28) hide show
  1. package/dist/module/notification/controller/otp.controller.d.ts +6 -1
  2. package/dist/module/notification/controller/otp.controller.js +5 -5
  3. package/dist/module/notification/controller/otp.controller.js.map +1 -1
  4. package/dist/module/notification/service/email.service.d.ts +4 -2
  5. package/dist/module/notification/service/email.service.js +13 -3
  6. package/dist/module/notification/service/email.service.js.map +1 -1
  7. package/dist/module/workflow/controller/action.controller.d.ts +3 -0
  8. package/dist/module/workflow/repository/action-data.repository.js +2 -0
  9. package/dist/module/workflow/repository/action-data.repository.js.map +1 -1
  10. package/dist/module/workflow/repository/action.repository.d.ts +3 -0
  11. package/dist/module/workflow/repository/action.repository.js +8 -2
  12. package/dist/module/workflow/repository/action.repository.js.map +1 -1
  13. package/dist/module/workflow/repository/task.repository.js +2 -0
  14. package/dist/module/workflow/repository/task.repository.js.map +1 -1
  15. package/dist/module/workflow/service/action.service.d.ts +3 -0
  16. package/dist/module/workflow/service/action.service.js +2 -1
  17. package/dist/module/workflow/service/action.service.js.map +1 -1
  18. package/dist/module/workflow/service/workflow-meta.service.js +4 -4
  19. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  20. package/dist/tsconfig.build.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/src/module/notification/controller/otp.controller.ts +14 -6
  23. package/src/module/notification/service/email.service.ts +19 -2
  24. package/src/module/workflow/repository/action-data.repository.ts +5 -0
  25. package/src/module/workflow/repository/action.repository.ts +8 -1
  26. package/src/module/workflow/repository/task.repository.ts +9 -0
  27. package/src/module/workflow/service/action.service.ts +6 -1
  28. package/src/module/workflow/service/workflow-meta.service.ts +4 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.20",
3
+ "version": "2.2.22",
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
 
@@ -25,6 +25,10 @@ export class ActionDataRepository {
25
25
 
26
26
  if (action.length > 0) {
27
27
  for (const act of action) {
28
+ const is_mandatory = await this.dataSource.query(
29
+ `SELECT code FROM cr_list_master_items WHERE id = ? and organization_id = ? LIMIT 1;`,
30
+ [act.action_requirement, loggedInUser.organization_id],
31
+ );
28
32
  const isFirst = act.sequence == minSequence;
29
33
  const actionData = this.actionDataRepo.create({
30
34
  stage_id: act.stage_id,
@@ -35,6 +39,7 @@ export class ActionDataRepository {
35
39
  mapped_entity_type,
36
40
  is_current: isFirst ? 'Y' : null,
37
41
  start_time: isFirst ? new Date() : null,
42
+ is_mandatory: is_mandatory[0]?.code === 'mandatory' ? true : false,
38
43
  } as ActionDataEntity);
39
44
  await this.actionDataRepo.save(actionData);
40
45
  }
@@ -29,7 +29,14 @@ export class ActionRepository {
29
29
  [stage_id],
30
30
  );
31
31
 
32
- if (!stageActions?.length) return [];
32
+ if (!stageActions?.length) {
33
+ return [
34
+ {
35
+ value: 0,
36
+ label: 'Generic',
37
+ },
38
+ ];
39
+ }
33
40
 
34
41
  const actionIds = stageActions.map((sa) => sa.action_id);
35
42
 
@@ -38,14 +38,23 @@ export class TaskRepository {
38
38
 
39
39
  if (action.length > 0) {
40
40
  for (const act of action) {
41
+ // search that is_mandatory is true or not in list_master_items for the given organization
42
+
43
+ const is_mandatory = await this.dataSource.query(
44
+ `SELECT code FROM cr_list_master_items WHERE id = ? and organization_id = ? LIMIT 1;`,
45
+ [act.action_requirement, loggedInUser.organization_id],
46
+ );
47
+
41
48
  const taskData = this.TaskRepository.create({
42
49
  stage_id: act.stage_id,
43
50
  user_id: loggedInUser.id,
44
51
  action_id: act.id,
45
52
  name: act.name,
46
53
  sequence: act.sequence,
54
+ is_mandatory: is_mandatory[0]?.code === 'mandatory' ? true : false,
47
55
  mapped_entity_id,
48
56
  mapped_entity_type,
57
+
49
58
  is_system: true,
50
59
  status: todoListMasterItemId[0]?.id,
51
60
  } as TaskDataEntity);
@@ -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,
@@ -151,13 +151,11 @@ export class WorkflowMetaService extends EntityServiceImpl {
151
151
  return `Initialized workflow with first stage (Stage ID: ${firstStage.id}).`;
152
152
  }
153
153
 
154
- //idhr
155
-
156
154
  // Case 2: Has next stage – move forward
157
- const stageDate = await this.getNextStage(currentStage);
155
+ const stageData = await this.getNextStage(currentStage);
158
156
 
159
- if (stageDate.hasNextStage) {
160
- const { nextStage } = stageDate;
157
+ if (stageData.hasNextStage) {
158
+ const { nextStage } = stageData;
161
159
  // Close current stage
162
160
  currentStage.end_date = now;
163
161
  currentStage.is_current = 'N';
@@ -179,7 +177,7 @@ export class WorkflowMetaService extends EntityServiceImpl {
179
177
  });
180
178
 
181
179
  this.populateActionService(
182
- currentStage.stage_id,
180
+ stageData.nextStage.id,
183
181
  loggedInUser,
184
182
  mapped_entity_id,
185
183
  mapped_entity_type,