fix: sonarcloud warning and code cleanup

This commit is contained in:
canove
2021-01-15 07:04:01 -03:00
parent 454fd6ce08
commit a0e6b7b2c7
11 changed files with 40 additions and 45 deletions

View File

@@ -35,8 +35,9 @@ const CreateUserService = async ({
"Check-email",
"An user with this email already exists.",
async value => {
if (!value) return false;
const emailExists = await User.findOne({
where: { email: value! }
where: { email: value }
});
return !emailExists;
}

View File

@@ -32,13 +32,11 @@ const CreateWhatsAppService = async ({
"Check-name",
"This whatsapp name is already used.",
async value => {
if (value) {
const whatsappFound = await Whatsapp.findOne({
where: { name: value }
});
return !whatsappFound;
}
return true;
if (!value) return false;
const nameExists = await Whatsapp.findOne({
where: { name: value }
});
return !nameExists;
}
),
isDefault: Yup.boolean().required()
@@ -52,9 +50,7 @@ const CreateWhatsAppService = async ({
const whatsappFound = await Whatsapp.findOne();
if (!whatsappFound) {
isDefault = !whatsappFound;
}
isDefault = !whatsappFound;
let oldDefaultWhatsapp: Whatsapp | null = null;

View File

@@ -1,7 +1,7 @@
import Whatsapp from "../../models/Whatsapp";
import AppError from "../../errors/AppError";
const DeleteWhatsApprService = async (id: string): Promise<void> => {
const DeleteWhatsAppService = async (id: string): Promise<void> => {
const whatsapp = await Whatsapp.findOne({
where: { id }
});
@@ -13,4 +13,4 @@ const DeleteWhatsApprService = async (id: string): Promise<void> => {
await whatsapp.destroy();
};
export default DeleteWhatsApprService;
export default DeleteWhatsAppService;