Merge pull request 'feat: update validation otp' (#145) from feat/otp-cancel into development
Reviewed-on: #145pull/147/head 1.6.5-alpha.1
commit
5b7df0e372
|
@ -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;
|
||||||
|
|
|
@ -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.',
|
||||||
);
|
);
|
||||||
|
|
|
@ -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({
|
||||||
|
|
Loading…
Reference in New Issue