fix: remove ticket from all users when deleted

This commit is contained in:
canove
2020-09-25 21:17:41 -03:00
parent 6c63abf29c
commit eb23775948
7 changed files with 25 additions and 12 deletions

View File

@@ -81,7 +81,7 @@ export const update = async (
});
}
io.to(ticket.status).emit("ticket", {
io.to(ticket.status).to(ticketId).emit("ticket", {
action: "updateStatus",
ticket
});
@@ -99,7 +99,7 @@ export const remove = async (
const io = getIO();
io.to(ticket.status)
.to("notification")
.to(ticketId)
.emit("ticket", {
action: "delete",
ticketId: +ticketId

View File

@@ -27,7 +27,7 @@ const UpdateContactService = async ({
const contact = await Contact.findOne({
where: { id: contactId },
attributes: ["id", "name", "number", "email"],
attributes: ["id", "name", "number", "email", "profilePicUrl"],
include: ["extraInfo"]
});

View File

@@ -22,7 +22,7 @@ const CreateMessageService = async ({
const ticket = await ShowTicketService(ticketId);
if (!ticket) {
throw new AppError("No ticket found with this ID");
throw new AppError("No ticket found with this ID", 404);
}
const message: Message = await ticket.$create("message", messageData);

View File

@@ -1,4 +1,5 @@
import { where, fn, col } from "sequelize";
import AppError from "../../errors/AppError";
import Message from "../../models/Message";
import Ticket from "../../models/Ticket";
import ShowTicketService from "../TicketServices/ShowTicketService";
@@ -24,7 +25,7 @@ const ListMessagesService = async ({
const ticket = await ShowTicketService(ticketId);
if (!ticket) {
throw new Error("No ticket found with this ID");
throw new AppError("No ticket found with this ID", 404);
}
const whereCondition = {

View File

@@ -21,7 +21,7 @@ const ShowTicketService = async (id: string | number): Promise<Ticket> => {
});
if (!ticket) {
throw new AppError("No ticket found with this ID");
throw new AppError("No ticket found with this ID", 404);
}
return ticket;

View File

@@ -293,11 +293,13 @@ const MessagesList = () => {
const { data } = await api.get("/messages/" + ticketId, {
params: { pageNumber },
});
setContact(data.ticket.contact);
setTicket(data.ticket);
dispatch({ type: "LOAD_MESSAGES", payload: data.messages });
setHasMore(data.hasMore);
setLoading(false);
if (pageNumber === 1 && data.messages.length > 1) {
scrollToBottom();
}
@@ -318,7 +320,7 @@ const MessagesList = () => {
useEffect(() => {
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
socket.emit("joinChatBox", ticketId, () => {});
socket.emit("joinChatBox", ticketId);
socket.on("appMessage", data => {
if (data.action === "create") {
@@ -330,6 +332,17 @@ const MessagesList = () => {
}
});
socket.on("ticket", data => {
if (data.action === "updateStatus") {
setTicket(data.ticket);
}
if (data.action === "delete") {
toast.success("The deleted sucessfully.");
history.push("/tickets");
}
});
socket.on("contact", data => {
if (data.action === "update") {
setContact(data.contact);
@@ -339,7 +352,7 @@ const MessagesList = () => {
return () => {
socket.disconnect();
};
}, [ticketId]);
}, [ticketId, history]);
const loadMore = () => {
setPageNumber(prevPageNumber => prevPageNumber + 1);
@@ -585,11 +598,12 @@ const MessagesList = () => {
subheader={
loading ? (
<Skeleton animation="wave" width={80} />
) : (
ticket.user &&
) : ticket.user ? (
`${i18n.t("messagesList.header.assignedTo")} ${
ticket.user.name
}`
) : (
"Pending"
)
}
/>

View File

@@ -17,8 +17,6 @@ const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
const handleDeleteTicket = async () => {
try {
await api.delete(`/tickets/${ticket.id}`);
toast.success("Ticket deletado com sucesso.");
history.push("/tickets");
} catch (err) {
toast.error("Erro ao deletar o ticket");
}