mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
fix: remove ticket from all users when deleted
This commit is contained in:
@@ -81,7 +81,7 @@ export const update = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
io.to(ticket.status).emit("ticket", {
|
io.to(ticket.status).to(ticketId).emit("ticket", {
|
||||||
action: "updateStatus",
|
action: "updateStatus",
|
||||||
ticket
|
ticket
|
||||||
});
|
});
|
||||||
@@ -99,7 +99,7 @@ export const remove = async (
|
|||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
io.to(ticket.status)
|
io.to(ticket.status)
|
||||||
.to("notification")
|
.to(ticketId)
|
||||||
.emit("ticket", {
|
.emit("ticket", {
|
||||||
action: "delete",
|
action: "delete",
|
||||||
ticketId: +ticketId
|
ticketId: +ticketId
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const UpdateContactService = async ({
|
|||||||
|
|
||||||
const contact = await Contact.findOne({
|
const contact = await Contact.findOne({
|
||||||
where: { id: contactId },
|
where: { id: contactId },
|
||||||
attributes: ["id", "name", "number", "email"],
|
attributes: ["id", "name", "number", "email", "profilePicUrl"],
|
||||||
include: ["extraInfo"]
|
include: ["extraInfo"]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const CreateMessageService = async ({
|
|||||||
const ticket = await ShowTicketService(ticketId);
|
const ticket = await ShowTicketService(ticketId);
|
||||||
|
|
||||||
if (!ticket) {
|
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);
|
const message: Message = await ticket.$create("message", messageData);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { where, fn, col } from "sequelize";
|
import { where, fn, col } from "sequelize";
|
||||||
|
import AppError from "../../errors/AppError";
|
||||||
import Message from "../../models/Message";
|
import Message from "../../models/Message";
|
||||||
import Ticket from "../../models/Ticket";
|
import Ticket from "../../models/Ticket";
|
||||||
import ShowTicketService from "../TicketServices/ShowTicketService";
|
import ShowTicketService from "../TicketServices/ShowTicketService";
|
||||||
@@ -24,7 +25,7 @@ const ListMessagesService = async ({
|
|||||||
const ticket = await ShowTicketService(ticketId);
|
const ticket = await ShowTicketService(ticketId);
|
||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
throw new Error("No ticket found with this ID");
|
throw new AppError("No ticket found with this ID", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereCondition = {
|
const whereCondition = {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const ShowTicketService = async (id: string | number): Promise<Ticket> => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
throw new AppError("No ticket found with this ID");
|
throw new AppError("No ticket found with this ID", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ticket;
|
return ticket;
|
||||||
|
|||||||
@@ -293,11 +293,13 @@ const MessagesList = () => {
|
|||||||
const { data } = await api.get("/messages/" + ticketId, {
|
const { data } = await api.get("/messages/" + ticketId, {
|
||||||
params: { pageNumber },
|
params: { pageNumber },
|
||||||
});
|
});
|
||||||
|
|
||||||
setContact(data.ticket.contact);
|
setContact(data.ticket.contact);
|
||||||
setTicket(data.ticket);
|
setTicket(data.ticket);
|
||||||
dispatch({ type: "LOAD_MESSAGES", payload: data.messages });
|
dispatch({ type: "LOAD_MESSAGES", payload: data.messages });
|
||||||
setHasMore(data.hasMore);
|
setHasMore(data.hasMore);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
if (pageNumber === 1 && data.messages.length > 1) {
|
if (pageNumber === 1 && data.messages.length > 1) {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
@@ -318,7 +320,7 @@ const MessagesList = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
socket.emit("joinChatBox", ticketId, () => {});
|
socket.emit("joinChatBox", ticketId);
|
||||||
|
|
||||||
socket.on("appMessage", data => {
|
socket.on("appMessage", data => {
|
||||||
if (data.action === "create") {
|
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 => {
|
socket.on("contact", data => {
|
||||||
if (data.action === "update") {
|
if (data.action === "update") {
|
||||||
setContact(data.contact);
|
setContact(data.contact);
|
||||||
@@ -339,7 +352,7 @@ const MessagesList = () => {
|
|||||||
return () => {
|
return () => {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
};
|
};
|
||||||
}, [ticketId]);
|
}, [ticketId, history]);
|
||||||
|
|
||||||
const loadMore = () => {
|
const loadMore = () => {
|
||||||
setPageNumber(prevPageNumber => prevPageNumber + 1);
|
setPageNumber(prevPageNumber => prevPageNumber + 1);
|
||||||
@@ -585,11 +598,12 @@ const MessagesList = () => {
|
|||||||
subheader={
|
subheader={
|
||||||
loading ? (
|
loading ? (
|
||||||
<Skeleton animation="wave" width={80} />
|
<Skeleton animation="wave" width={80} />
|
||||||
) : (
|
) : ticket.user ? (
|
||||||
ticket.user &&
|
|
||||||
`${i18n.t("messagesList.header.assignedTo")} ${
|
`${i18n.t("messagesList.header.assignedTo")} ${
|
||||||
ticket.user.name
|
ticket.user.name
|
||||||
}`
|
}`
|
||||||
|
) : (
|
||||||
|
"Pending"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
|||||||
const handleDeleteTicket = async () => {
|
const handleDeleteTicket = async () => {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/tickets/${ticket.id}`);
|
await api.delete(`/tickets/${ticket.id}`);
|
||||||
toast.success("Ticket deletado com sucesso.");
|
|
||||||
history.push("/tickets");
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error("Erro ao deletar o ticket");
|
toast.error("Erro ao deletar o ticket");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user