otp check if user exists in region

This commit is contained in:
yousef-alkhrissat
2024-08-09 18:54:53 +03:00
parent 842e64a4d1
commit 9667625562
2 changed files with 18 additions and 2 deletions

View File

@ -12,6 +12,11 @@ export class UserOtpDto {
@IsEnum(OtpType)
@IsNotEmpty()
type: OtpType;
@ApiProperty()
@IsNotEmpty()
@IsString()
regionName: string;
}
export class VerifyOtpDto extends UserOtpDto {

View File

@ -116,7 +116,7 @@ export class UserAuthService {
async deleteUser(uuid: string) {
const user = await this.findOneById(uuid);
if (!user) {
throw new BadRequestException('User does not found');
throw new BadRequestException('User not found');
}
return await this.userRepository.update({ uuid }, { isActive: false });
}
@ -128,6 +128,17 @@ export class UserAuthService {
async generateOTP(data: UserOtpDto): Promise<string> {
const threeDaysAgo = new Date();
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
const userExists = await this.userRepository.exists({
where: {
region: {
regionName: data.regionName,
},
email: data.email,
},
});
if (!userExists) {
throw new BadRequestException('User not found');
}
await this.otpRepository.softDelete({ email: data.email, type: data.type });
await this.otpRepository.delete({
email: data.email,
@ -153,7 +164,7 @@ export class UserAuthService {
const timeSinceLastOtp = differenceInSeconds(now, lastOtp.createdAt);
if (timeSinceLastOtp < cooldown) {
throw new Error(
throw new BadRequestException(
`Please wait ${cooldown - timeSinceLastOtp} more seconds before requesting a new OTP.`,
);
}