mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
fix: sonarcloud warning and code cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
import AppError from "../../../errors/AppError";
|
import AppError from "../../../errors/AppError";
|
||||||
import AuthUserService from "../../../services/UserServices/AuthUserSerice";
|
import AuthUserService from "../../../services/UserServices/AuthUserService";
|
||||||
import CreateUserService from "../../../services/UserServices/CreateUserService";
|
import CreateUserService from "../../../services/UserServices/CreateUserService";
|
||||||
import { disconnect, truncate } from "../../utils/database";
|
import { disconnect, truncate } from "../../utils/database";
|
||||||
|
|
||||||
@@ -18,15 +18,18 @@ describe("Auth", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should be able to login with an existing user", async () => {
|
it("should be able to login with an existing user", async () => {
|
||||||
|
const password = faker.internet.password();
|
||||||
|
const email = faker.internet.email();
|
||||||
|
|
||||||
await CreateUserService({
|
await CreateUserService({
|
||||||
name: faker.name.findName(),
|
name: faker.name.findName(),
|
||||||
email: "mail@test.com",
|
email,
|
||||||
password: "hardpassword"
|
password
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await AuthUserService({
|
const response = await AuthUserService({
|
||||||
email: "mail@test.com",
|
email,
|
||||||
password: "hardpassword"
|
password
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(response).toHaveProperty("token");
|
expect(response).toHaveProperty("token");
|
||||||
@@ -49,7 +52,7 @@ describe("Auth", () => {
|
|||||||
await CreateUserService({
|
await CreateUserService({
|
||||||
name: faker.name.findName(),
|
name: faker.name.findName(),
|
||||||
email: "mail@test.com",
|
email: "mail@test.com",
|
||||||
password: "hardpassword"
|
password: faker.internet.password()
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import AppError from "../errors/AppError";
|
import AppError from "../errors/AppError";
|
||||||
|
|
||||||
import AuthUserService from "../services/UserServices/AuthUserSerice";
|
import AuthUserService from "../services/UserServices/AuthUserService";
|
||||||
import { SendRefreshToken } from "../helpers/SendRefreshToken";
|
import { SendRefreshToken } from "../helpers/SendRefreshToken";
|
||||||
import { RefreshTokenService } from "../services/AuthServices/RefreshTokenService";
|
import { RefreshTokenService } from "../services/AuthServices/RefreshTokenService";
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,9 @@ const CreateUserService = async ({
|
|||||||
"Check-email",
|
"Check-email",
|
||||||
"An user with this email already exists.",
|
"An user with this email already exists.",
|
||||||
async value => {
|
async value => {
|
||||||
|
if (!value) return false;
|
||||||
const emailExists = await User.findOne({
|
const emailExists = await User.findOne({
|
||||||
where: { email: value! }
|
where: { email: value }
|
||||||
});
|
});
|
||||||
return !emailExists;
|
return !emailExists;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,13 +32,11 @@ const CreateWhatsAppService = async ({
|
|||||||
"Check-name",
|
"Check-name",
|
||||||
"This whatsapp name is already used.",
|
"This whatsapp name is already used.",
|
||||||
async value => {
|
async value => {
|
||||||
if (value) {
|
if (!value) return false;
|
||||||
const whatsappFound = await Whatsapp.findOne({
|
const nameExists = await Whatsapp.findOne({
|
||||||
where: { name: value }
|
where: { name: value }
|
||||||
});
|
});
|
||||||
return !whatsappFound;
|
return !nameExists;
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
isDefault: Yup.boolean().required()
|
isDefault: Yup.boolean().required()
|
||||||
@@ -52,9 +50,7 @@ const CreateWhatsAppService = async ({
|
|||||||
|
|
||||||
const whatsappFound = await Whatsapp.findOne();
|
const whatsappFound = await Whatsapp.findOne();
|
||||||
|
|
||||||
if (!whatsappFound) {
|
|
||||||
isDefault = !whatsappFound;
|
isDefault = !whatsappFound;
|
||||||
}
|
|
||||||
|
|
||||||
let oldDefaultWhatsapp: Whatsapp | null = null;
|
let oldDefaultWhatsapp: Whatsapp | null = null;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Whatsapp from "../../models/Whatsapp";
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
|
|
||||||
const DeleteWhatsApprService = async (id: string): Promise<void> => {
|
const DeleteWhatsAppService = async (id: string): Promise<void> => {
|
||||||
const whatsapp = await Whatsapp.findOne({
|
const whatsapp = await Whatsapp.findOne({
|
||||||
where: { id }
|
where: { id }
|
||||||
});
|
});
|
||||||
@@ -13,4 +13,4 @@ const DeleteWhatsApprService = async (id: string): Promise<void> => {
|
|||||||
await whatsapp.destroy();
|
await whatsapp.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DeleteWhatsApprService;
|
export default DeleteWhatsAppService;
|
||||||
|
|||||||
@@ -102,12 +102,8 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => {
|
|||||||
fetchContact();
|
fetchContact();
|
||||||
}, [contactId, open, initialValues]);
|
}, [contactId, open, initialValues]);
|
||||||
|
|
||||||
const handleClose = contactId => {
|
const handleClose = () => {
|
||||||
if (contactId) {
|
|
||||||
onClose(contactId);
|
|
||||||
} else {
|
|
||||||
onClose();
|
onClose();
|
||||||
}
|
|
||||||
setContact(initialState);
|
setContact(initialState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ const MarkdownWrapper = ({ children }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const options = React.useMemo(() => {
|
const options = React.useMemo(() => {
|
||||||
const options = {
|
const markdownOptions = {
|
||||||
disableParsingRawHTML: true,
|
disableParsingRawHTML: true,
|
||||||
forceInline: true,
|
forceInline: true,
|
||||||
overrides: {
|
overrides: {
|
||||||
@@ -171,11 +171,11 @@ const MarkdownWrapper = ({ children }) => {
|
|||||||
|
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
if (!allowedElements.includes(element)) {
|
if (!allowedElements.includes(element)) {
|
||||||
options.overrides[element] = ({ children }) => children;
|
markdownOptions.overrides[element] = el => el.children;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return options;
|
return markdownOptions;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <Markdown options={options}>{children}</Markdown>;
|
return <Markdown options={options}>{children}</Markdown>;
|
||||||
|
|||||||
@@ -100,8 +100,8 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
|
|||||||
handleSaveTicket(contact.id);
|
handleSaveTicket(contact.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createAddContactOption = (options, params) => {
|
const createAddContactOption = (filterOptions, params) => {
|
||||||
const filtered = filter(options, params);
|
const filtered = filter(filterOptions, params);
|
||||||
|
|
||||||
if (params.inputValue !== "" && !loading && searchParam.length >= 3) {
|
if (params.inputValue !== "" && !loading && searchParam.length >= 3) {
|
||||||
filtered.push({
|
filtered.push({
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import ButtonWithSpinner from "../ButtonWithSpinner";
|
|||||||
import MarkdownWrapper from "../MarkdownWrapper";
|
import MarkdownWrapper from "../MarkdownWrapper";
|
||||||
import { Tooltip } from "@material-ui/core";
|
import { Tooltip } from "@material-ui/core";
|
||||||
import { AuthContext } from "../../context/Auth/AuthContext";
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
ticket: {
|
ticket: {
|
||||||
@@ -114,25 +115,25 @@ const TicketListItem = ({ ticket }) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleAcepptTicket = async ticketId => {
|
const handleAcepptTicket = async id => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await api.put(`/tickets/${ticketId}`, {
|
await api.put(`/tickets/${id}`, {
|
||||||
status: "open",
|
status: "open",
|
||||||
userId: user?.id,
|
userId: user?.id,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
alert(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
history.push(`/tickets/${ticketId}`);
|
history.push(`/tickets/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectTicket = (e, ticket) => {
|
const handleSelectTicket = id => {
|
||||||
history.push(`/tickets/${ticket.id}`);
|
history.push(`/tickets/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -142,7 +143,7 @@ const TicketListItem = ({ ticket }) => {
|
|||||||
button
|
button
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
if (ticket.status === "pending") return;
|
if (ticket.status === "pending") return;
|
||||||
handleSelectTicket(e, ticket);
|
handleSelectTicket(ticket.id);
|
||||||
}}
|
}}
|
||||||
selected={ticketId && +ticketId === ticket.id}
|
selected={ticketId && +ticketId === ticket.id}
|
||||||
className={clsx(classes.ticket, {
|
className={clsx(classes.ticket, {
|
||||||
@@ -160,9 +161,7 @@ const TicketListItem = ({ ticket }) => {
|
|||||||
></span>
|
></span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<ListItemAvatar>
|
<ListItemAvatar>
|
||||||
<Avatar
|
<Avatar src={ticket?.contact?.profilePicUrl} />
|
||||||
src={ticket.contact.profilePicUrl && ticket.contact.profilePicUrl}
|
|
||||||
></Avatar>
|
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
disableTypography
|
disableTypography
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { Route, Redirect } from "react-router-dom";
|
import { Route as RouterRoute, Redirect } from "react-router-dom";
|
||||||
|
|
||||||
import { AuthContext } from "../context/Auth/AuthContext";
|
import { AuthContext } from "../context/Auth/AuthContext";
|
||||||
import BackdropLoading from "../components/BackdropLoading";
|
import BackdropLoading from "../components/BackdropLoading";
|
||||||
|
|
||||||
const RouteWrapper = ({ component: Component, isPrivate = false, ...rest }) => {
|
const Route = ({ component: Component, isPrivate = false, ...rest }) => {
|
||||||
const { isAuth, loading } = useContext(AuthContext);
|
const { isAuth, loading } = useContext(AuthContext);
|
||||||
|
|
||||||
if (!isAuth && isPrivate) {
|
if (!isAuth && isPrivate) {
|
||||||
@@ -28,9 +28,9 @@ const RouteWrapper = ({ component: Component, isPrivate = false, ...rest }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{loading && <BackdropLoading />}
|
{loading && <BackdropLoading />}
|
||||||
<Route {...rest} component={Component} />
|
<RouterRoute {...rest} component={Component} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RouteWrapper;
|
export default Route;
|
||||||
|
|||||||
Reference in New Issue
Block a user