Correção do bug tcp_wrap que ocorriga quando um usuario era atualizado com um email que ja esta cadastrado no banco
parent
67fbaaef88
commit
5073ccadf7
|
@ -29,7 +29,7 @@ const CreateUserService = async ({
|
|||
const schema = Yup.object().shape({
|
||||
name: Yup.string().required().min(2),
|
||||
|
||||
email: Yup.string().required().test(
|
||||
email: Yup.string().required().trim().test(
|
||||
"Check-email",
|
||||
"An user with this email already exists.",
|
||||
async value => {
|
||||
|
@ -58,7 +58,7 @@ const CreateUserService = async ({
|
|||
|
||||
try {
|
||||
await schema.validate({ email, password, name });
|
||||
} catch (err) {
|
||||
} catch (err:any) {
|
||||
throw new AppError(err.message);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|||
|
||||
import AppError from "../../errors/AppError";
|
||||
import ShowUserService from "./ShowUserService";
|
||||
import User from "../../models/User";
|
||||
|
||||
interface UserData {
|
||||
email?: string;
|
||||
|
@ -31,13 +32,22 @@ const UpdateUserService = async ({
|
|||
|
||||
const schema = Yup.object().shape({
|
||||
name: Yup.string().min(2),
|
||||
|
||||
email: Yup.string().min(2),
|
||||
|
||||
// email: Yup.string().email(),
|
||||
|
||||
// email: Yup.string().min(2),
|
||||
profile: Yup.string(),
|
||||
password: Yup.string()
|
||||
password: Yup.string(),
|
||||
|
||||
email: Yup.string().trim().required().test(
|
||||
"Check-email",
|
||||
"An user with this email already exists.",
|
||||
async value => {
|
||||
if (!value) return false;
|
||||
const emailExists = await User.findOne({
|
||||
where: { email: value }
|
||||
});
|
||||
return !emailExists;
|
||||
}
|
||||
),
|
||||
|
||||
});
|
||||
|
||||
const { email, password, profile, name, queueIds = [] } = userData;
|
||||
|
@ -48,6 +58,7 @@ const UpdateUserService = async ({
|
|||
throw new AppError(err.message);
|
||||
}
|
||||
|
||||
|
||||
await user.update({
|
||||
email,
|
||||
password,
|
||||
|
|
Loading…
Reference in New Issue