auth defined test required

This commit is contained in:
2025-07-27 15:54:23 +03:00
parent f39dc541e1
commit 6cf7ce1397
17 changed files with 857 additions and 147 deletions

View File

@@ -1,8 +1,36 @@
import { Injectable } from '@nestjs/common';
import { Injectable, BadRequestException } from '@nestjs/common';
import { userResetPasswordValidator } from './dtoValidator';
import { PrismaService } from '@/src/prisma.service';
import { PasswordHandlers } from '@/src/utils/auth/login_handler';
@Injectable()
export class ResetPasswordService {
async run(dto: any) {
return dto;
constructor(
private readonly prisma: PrismaService,
private readonly passHandlers: PasswordHandlers,
) {}
async run(dto: userResetPasswordValidator) {
const foundUser = await this.prisma.users.findFirstOrThrow({
where: {
OR: [{ email: dto.accessKey }, { phone_number: dto.accessKey }],
},
});
if (!foundUser) {
throw new BadRequestException(
'User not found. Please check your email or phone number',
);
}
await this.prisma.users.update({
where: { id: foundUser.id },
data: {
password_token: this.passHandlers.generateRefreshToken(),
password_expiry_begins: new Date(),
password_expires_day: 30,
},
});
return {
message: 'Password reset token sent successfully',
};
}
}