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({
|
const schema = Yup.object().shape({
|
||||||
name: Yup.string().required().min(2),
|
name: Yup.string().required().min(2),
|
||||||
|
|
||||||
email: Yup.string().required().test(
|
email: Yup.string().required().trim().test(
|
||||||
"Check-email",
|
"Check-email",
|
||||||
"An user with this email already exists.",
|
"An user with this email already exists.",
|
||||||
async value => {
|
async value => {
|
||||||
|
@ -58,7 +58,7 @@ const CreateUserService = async ({
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await schema.validate({ email, password, name });
|
await schema.validate({ email, password, name });
|
||||||
} catch (err) {
|
} catch (err:any) {
|
||||||
throw new AppError(err.message);
|
throw new AppError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as Yup from "yup";
|
||||||
|
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
import ShowUserService from "./ShowUserService";
|
import ShowUserService from "./ShowUserService";
|
||||||
|
import User from "../../models/User";
|
||||||
|
|
||||||
interface UserData {
|
interface UserData {
|
||||||
email?: string;
|
email?: string;
|
||||||
|
@ -31,13 +32,22 @@ const UpdateUserService = async ({
|
||||||
|
|
||||||
const schema = Yup.object().shape({
|
const schema = Yup.object().shape({
|
||||||
name: Yup.string().min(2),
|
name: Yup.string().min(2),
|
||||||
|
// email: Yup.string().min(2),
|
||||||
email: Yup.string().min(2),
|
|
||||||
|
|
||||||
// email: Yup.string().email(),
|
|
||||||
|
|
||||||
profile: Yup.string(),
|
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;
|
const { email, password, profile, name, queueIds = [] } = userData;
|
||||||
|
@ -48,6 +58,7 @@ const UpdateUserService = async ({
|
||||||
throw new AppError(err.message);
|
throw new AppError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await user.update({
|
await user.update({
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
|
|
Loading…
Reference in New Issue