mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
fix: sonarcloud warning and code cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import faker from "faker";
|
||||
import AppError from "../../../errors/AppError";
|
||||
import AuthUserService from "../../../services/UserServices/AuthUserSerice";
|
||||
import AuthUserService from "../../../services/UserServices/AuthUserService";
|
||||
import CreateUserService from "../../../services/UserServices/CreateUserService";
|
||||
import { disconnect, truncate } from "../../utils/database";
|
||||
|
||||
@@ -18,15 +18,18 @@ describe("Auth", () => {
|
||||
});
|
||||
|
||||
it("should be able to login with an existing user", async () => {
|
||||
const password = faker.internet.password();
|
||||
const email = faker.internet.email();
|
||||
|
||||
await CreateUserService({
|
||||
name: faker.name.findName(),
|
||||
email: "mail@test.com",
|
||||
password: "hardpassword"
|
||||
email,
|
||||
password
|
||||
});
|
||||
|
||||
const response = await AuthUserService({
|
||||
email: "mail@test.com",
|
||||
password: "hardpassword"
|
||||
email,
|
||||
password
|
||||
});
|
||||
|
||||
expect(response).toHaveProperty("token");
|
||||
@@ -49,7 +52,7 @@ describe("Auth", () => {
|
||||
await CreateUserService({
|
||||
name: faker.name.findName(),
|
||||
email: "mail@test.com",
|
||||
password: "hardpassword"
|
||||
password: faker.internet.password()
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from "express";
|
||||
import AppError from "../errors/AppError";
|
||||
|
||||
import AuthUserService from "../services/UserServices/AuthUserSerice";
|
||||
import AuthUserService from "../services/UserServices/AuthUserService";
|
||||
import { SendRefreshToken } from "../helpers/SendRefreshToken";
|
||||
import { RefreshTokenService } from "../services/AuthServices/RefreshTokenService";
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user