rez_core 2.2.94 → 2.2.96

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.94",
3
+ "version": "2.2.96",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -462,6 +462,18 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
462
462
  );
463
463
  }
464
464
 
465
+ async getSingleResolvedData(
466
+ loggedInUser: UserData,
467
+ entityData: any,
468
+ entityType: string,
469
+ ): Promise<any> {
470
+ return this.resolverService.getResolvedData(
471
+ loggedInUser,
472
+ entityData,
473
+ entityType,
474
+ );
475
+ }
476
+
465
477
  async getResolvedEntityData(
466
478
  entityType: string,
467
479
  entityId: number,
@@ -1,9 +1,11 @@
1
+ import { DataSource } from 'typeorm';
1
2
  import { BadRequestException, Injectable } from '@nestjs/common';
2
3
  import { ConfigService } from '@nestjs/config';
3
4
  import { ClockIDGenService } from '../../../utils/service/clockIDGenUtil.service';
4
5
  import { Otp } from '../entity/otp.entity';
5
6
  import { OtpRepository } from '../repository/otp.repository';
6
7
  import { LoginService } from './../../user/service/login.service';
8
+ import { EmailService } from './email.service';
7
9
 
8
10
  @Injectable()
9
11
  export class OtpService {
@@ -12,6 +14,8 @@ export class OtpService {
12
14
  private readonly idGen: ClockIDGenService,
13
15
  private configService: ConfigService,
14
16
  private readonly loginService: LoginService,
17
+ private readonly emailService: EmailService,
18
+ private readonly dataSource: DataSource,
15
19
  ) {}
16
20
 
17
21
  VERIFY_OTP = this.configService.get('VERIFY_OTP') || 'true';
@@ -35,44 +39,60 @@ export class OtpService {
35
39
  otp.verified = 0;
36
40
  otp.expiration_date = new Date(Date.now() + expiresIn * 60 * 1000);
37
41
 
42
+ const userData = await this.dataSource
43
+ .getRepository('cr_user')
44
+ .findOne({ where: { email_id: identifier } });
45
+
46
+ const data = {
47
+ name: userData?.name || '',
48
+ otp: otp.otp,
49
+ };
50
+
51
+ await this.emailService.sendEmail(identifier, 'OTP Verification', data);
52
+
38
53
  return await this.otpRepository.save(otp);
39
54
  }
40
55
 
41
56
  async verifyOtp(body: { otp: string; otp_id: string; identifier: string }) {
42
- let verifyOTPResponse = {
43
- isValid: false,
44
- };
57
+ const { otp, otp_id, identifier } = body;
58
+ const verifyOTPResponse = { isValid: false };
45
59
 
46
- let otp = body.otp;
47
- let otpId = body.otp_id;
60
+ // Find OTP entity by ID
61
+ const otpEntity = await this.findByOtpId(otp_id);
62
+ if (!otpEntity) {
63
+ throw new BadRequestException('OTP not found!');
64
+ }
48
65
 
49
- let otpEntity = await this.findByOtpId(otpId);
66
+ // Validate the identifier against the OTP entity
67
+ if (otpEntity.identifier !== identifier) {
68
+ throw new BadRequestException('Invalid OTP identifier!');
69
+ }
50
70
 
51
- if (otpEntity) {
52
- if (otpEntity.identifier !== body.identifier) {
53
- throw new BadRequestException('Invalid OTP!');
54
- }
71
+ // OTP validation logic
72
+ const isOtpValid =
73
+ otpEntity.otp === otp &&
74
+ new Date() <= otpEntity.expiration_date &&
75
+ otpEntity.verified === 0;
55
76
 
56
- if (
57
- otpEntity.otp === otp &&
58
- new Date(Date.now()) <= otpEntity.expiration_date &&
59
- 0 === otpEntity.verified
60
- ) {
61
- otpEntity.verified = 1;
62
- const updatedOtp = await this.otpRepository.update(
63
- otpEntity.id,
64
- otpEntity,
65
- );
66
- if (updatedOtp) {
67
- verifyOTPResponse.isValid = true;
68
- }
77
+ if (isOtpValid) {
78
+ otpEntity.verified = 1;
79
+
80
+ // Save the updated OTP status
81
+ const updatedOtp = await this.otpRepository.update(
82
+ otpEntity.id,
83
+ otpEntity,
84
+ );
85
+ if (updatedOtp) {
86
+ verifyOTPResponse.isValid = true;
69
87
  }
70
88
  }
71
89
 
72
90
  if (!verifyOTPResponse.isValid) {
73
91
  throw new BadRequestException('Invalid OTP!');
74
92
  }
75
- return await this.loginService.login(body.identifier, undefined, true);
93
+
94
+ // Proceed to login
95
+ return this.loginService.login(identifier, undefined, true);
76
96
  }
77
97
 
78
98
  async findByOtpId(otpId: string) {