auth defined test required
This commit is contained in:
@@ -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',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user