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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import * as Yup from "yup";
|
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;
|
||||||
|
@ -30,14 +31,23 @@ const UpdateUserService = async ({
|
||||||
const user = await ShowUserService(userId);
|
const user = await ShowUserService(userId);
|
||||||
|
|
||||||
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;
|
||||||
|
@ -47,6 +57,7 @@ const UpdateUserService = async ({
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
throw new AppError(err.message);
|
throw new AppError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await user.update({
|
await user.update({
|
||||||
email,
|
email,
|
||||||
|
|
Loading…
Reference in New Issue