mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
otp check if user exists in region
This commit is contained in:
@ -12,6 +12,11 @@ export class UserOtpDto {
|
||||
@IsEnum(OtpType)
|
||||
@IsNotEmpty()
|
||||
type: OtpType;
|
||||
|
||||
@ApiProperty()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
regionName: string;
|
||||
}
|
||||
|
||||
export class VerifyOtpDto extends UserOtpDto {
|
||||
|
@ -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.`,
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user