From ca886069f1324dde637b5e2f508d142150abc170 Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:45:58 +0700 Subject: [PATCH] feat: update validation otp --- src/core/helpers/otp/otp-service.ts | 3 ++- .../data/services/otp-verification.service.ts | 6 +++--- .../transaction/vip-code/infrastructure/dto/vip-code.dto.ts | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/helpers/otp/otp-service.ts b/src/core/helpers/otp/otp-service.ts index e5f9433..f63057b 100644 --- a/src/core/helpers/otp/otp-service.ts +++ b/src/core/helpers/otp/otp-service.ts @@ -49,7 +49,8 @@ export class OtpService { this.hasSequentialDigits(otp) || this.hasRepeatedDigits(otp) || this.isPalindrome(otp) || - this.hasPartiallyRepeatedDigits(otp) + this.hasPartiallyRepeatedDigits(otp) || + otp?.split('')?.length < this.otpLength ); return otp; diff --git a/src/modules/configuration/otp-verification/data/services/otp-verification.service.ts b/src/modules/configuration/otp-verification/data/services/otp-verification.service.ts index 7905606..11420d2 100644 --- a/src/modules/configuration/otp-verification/data/services/otp-verification.service.ts +++ b/src/modules/configuration/otp-verification/data/services/otp-verification.service.ts @@ -29,7 +29,7 @@ export class OtpVerificationService { return moment().add(minutes, 'minutes').valueOf(); // epoch millis expired time } - private generateResendAvailableAt(seconds = 90): number { + private generateResendAvailableAt(seconds = 60): number { return moment().add(seconds, 'seconds').valueOf(); // epoch millis } @@ -67,14 +67,14 @@ export class OtpVerificationService { }; const activeOTP = await this.getActiveOtp( - payload.target_id ?? payload.reference, + payload.target_id ? payload.target_id : payload.reference, ); if (activeOTP) { const createdAtMoment = moment(Number(activeOTP.created_at)); const nowMoment = moment(Number(dateNow)); const diffSeconds = nowMoment.diff(createdAtMoment, 'seconds'); - if (diffSeconds < 90) { + if (diffSeconds < 60) { throw new BadRequestException( 'An active OTP request was made recently. Please try again later.', ); diff --git a/src/modules/transaction/vip-code/infrastructure/dto/vip-code.dto.ts b/src/modules/transaction/vip-code/infrastructure/dto/vip-code.dto.ts index 1666c7f..be762ae 100644 --- a/src/modules/transaction/vip-code/infrastructure/dto/vip-code.dto.ts +++ b/src/modules/transaction/vip-code/infrastructure/dto/vip-code.dto.ts @@ -1,6 +1,6 @@ import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto'; import { VipCodeEntity } from '../../domain/entities/vip-code.entity'; -import { IsNumber, IsObject, IsString } from 'class-validator'; +import { IsNumber, IsObject, IsString, ValidateIf } from 'class-validator'; import { ApiProperty } from '@nestjs/swagger'; export class VipCodeDto extends BaseDto implements VipCodeEntity { @@ -29,6 +29,7 @@ export class VipCodeDto extends BaseDto implements VipCodeEntity { example: 25000, }) @IsNumber() + @ValidateIf((v) => v.discount_value) discount_value: number; @ApiProperty({