chore: user setting module

This commit is contained in:
Matin
2025-02-03 15:30:49 +03:30
parent 014aaf353d
commit 957178261e
25 changed files with 465 additions and 52 deletions
@@ -9,6 +9,7 @@ import { PasswordService } from "../../utils/providers/password.service";
import { CompleteRegistrationDto } from "../DTO/complete-register.dto";
import { CheckUserExistDto, LoginPasswordDTO } from "../DTO/loginPassword.dto";
import { RequestOtpDto } from "../DTO/request-otp.dto";
import { UpdatePasswordDto } from "../DTO/update-password.dto";
import { VerifyOtpDto } from "../DTO/verify-otp.dto";
@Injectable()
@@ -152,6 +153,23 @@ export class AuthService {
};
}
//****************** */
async updatePassword(userId: string, updateDto: UpdatePasswordDto) {
const { user } = await this.usersService.findOneById(userId);
const passCompare = await this.passwordService.comparePassword(updateDto.password, user.password);
if (!passCompare) throw new BadRequestException(AuthMessage.INVALID_PASSWORD);
if (updateDto.newPassword !== updateDto.repeatPassword) throw new BadRequestException(AuthMessage.INVALID_REAPET_PASSWORD);
const hashedPassword = await this.passwordService.hashPassword(updateDto.newPassword);
await this.usersService.updateUserPassword(user.id, hashedPassword);
return {
message: AuthMessage.PASSWORD_CHANGED_SUCCESSFULLY,
};
}
//****************** */
private async checkUserLoginCredentialWithEmail(email: string, password: string) {