feat: update validation otp #145

Merged
firmanr merged 1 commits from feat/otp-cancel into development 2025-06-05 16:46:45 +07:00
3 changed files with 7 additions and 5 deletions

View File

@ -49,7 +49,8 @@ export class OtpService {
this.hasSequentialDigits(otp) || this.hasSequentialDigits(otp) ||
this.hasRepeatedDigits(otp) || this.hasRepeatedDigits(otp) ||
this.isPalindrome(otp) || this.isPalindrome(otp) ||
this.hasPartiallyRepeatedDigits(otp) this.hasPartiallyRepeatedDigits(otp) ||
otp?.split('')?.length < this.otpLength
); );
return otp; return otp;

View File

@ -29,7 +29,7 @@ export class OtpVerificationService {
return moment().add(minutes, 'minutes').valueOf(); // epoch millis expired time 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 return moment().add(seconds, 'seconds').valueOf(); // epoch millis
} }
@ -67,14 +67,14 @@ export class OtpVerificationService {
}; };
const activeOTP = await this.getActiveOtp( const activeOTP = await this.getActiveOtp(
payload.target_id ?? payload.reference, payload.target_id ? payload.target_id : payload.reference,
); );
if (activeOTP) { if (activeOTP) {
const createdAtMoment = moment(Number(activeOTP.created_at)); const createdAtMoment = moment(Number(activeOTP.created_at));
const nowMoment = moment(Number(dateNow)); const nowMoment = moment(Number(dateNow));
const diffSeconds = nowMoment.diff(createdAtMoment, 'seconds'); const diffSeconds = nowMoment.diff(createdAtMoment, 'seconds');
if (diffSeconds < 90) { if (diffSeconds < 60) {
throw new BadRequestException( throw new BadRequestException(
'An active OTP request was made recently. Please try again later.', 'An active OTP request was made recently. Please try again later.',
); );

View File

@ -1,6 +1,6 @@
import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto'; import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto';
import { VipCodeEntity } from '../../domain/entities/vip-code.entity'; 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'; import { ApiProperty } from '@nestjs/swagger';
export class VipCodeDto extends BaseDto implements VipCodeEntity { export class VipCodeDto extends BaseDto implements VipCodeEntity {
@ -29,6 +29,7 @@ export class VipCodeDto extends BaseDto implements VipCodeEntity {
example: 25000, example: 25000,
}) })
@IsNumber() @IsNumber()
@ValidateIf((v) => v.discount_value)
discount_value: number; discount_value: number;
@ApiProperty({ @ApiProperty({