mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
otp check if user exists in region
This commit is contained in:
@ -12,6 +12,11 @@ export class UserOtpDto {
|
|||||||
@IsEnum(OtpType)
|
@IsEnum(OtpType)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
type: OtpType;
|
type: OtpType;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
regionName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class VerifyOtpDto extends UserOtpDto {
|
export class VerifyOtpDto extends UserOtpDto {
|
||||||
|
@ -116,7 +116,7 @@ export class UserAuthService {
|
|||||||
async deleteUser(uuid: string) {
|
async deleteUser(uuid: string) {
|
||||||
const user = await this.findOneById(uuid);
|
const user = await this.findOneById(uuid);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new BadRequestException('User does not found');
|
throw new BadRequestException('User not found');
|
||||||
}
|
}
|
||||||
return await this.userRepository.update({ uuid }, { isActive: false });
|
return await this.userRepository.update({ uuid }, { isActive: false });
|
||||||
}
|
}
|
||||||
@ -128,6 +128,17 @@ export class UserAuthService {
|
|||||||
async generateOTP(data: UserOtpDto): Promise<string> {
|
async generateOTP(data: UserOtpDto): Promise<string> {
|
||||||
const threeDaysAgo = new Date();
|
const threeDaysAgo = new Date();
|
||||||
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
|
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.softDelete({ email: data.email, type: data.type });
|
||||||
await this.otpRepository.delete({
|
await this.otpRepository.delete({
|
||||||
email: data.email,
|
email: data.email,
|
||||||
@ -153,7 +164,7 @@ export class UserAuthService {
|
|||||||
const timeSinceLastOtp = differenceInSeconds(now, lastOtp.createdAt);
|
const timeSinceLastOtp = differenceInSeconds(now, lastOtp.createdAt);
|
||||||
|
|
||||||
if (timeSinceLastOtp < cooldown) {
|
if (timeSinceLastOtp < cooldown) {
|
||||||
throw new Error(
|
throw new BadRequestException(
|
||||||
`Please wait ${cooldown - timeSinceLastOtp} more seconds before requesting a new OTP.`,
|
`Please wait ${cooldown - timeSinceLastOtp} more seconds before requesting a new OTP.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user