feat: add reset password service

feat-scaling-ticket-remote-creation
Henrriky 2024-03-12 17:18:41 -03:00
parent d608538c9e
commit 895ce83b5b
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import * as Yup from "yup";
import AppError from "../../errors/AppError";
import ShowUserService from "./ShowUserService";
interface ResetPasswordServiceRequest {
userPassword: string;
userId: string | number;
}
const ResetPasswordService = async ({userPassword, userId}: ResetPasswordServiceRequest): Promise<void> => {
try {
const user = await ShowUserService(userId);
const schema = Yup.object().shape({
password: Yup.string(),
});
try {
await schema.validate({ password: userPassword });
} catch (err: any) {
throw new AppError(err.message);
}
await user.update({
userPassword,
});
await user.reload();
} catch (error: any) {
console.error('===> Error on ResetPasswordService.ts file: \n', error)
throw new AppError(error.message);
}
};
export default ResetPasswordService;