mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 11:49:19 +00:00
fix: tickets not disappearing for users that are not members of queue after queue assignment
This commit is contained in:
@@ -85,25 +85,11 @@ export const update = async (
|
||||
const { ticketId } = req.params;
|
||||
const ticketData: TicketData = req.body;
|
||||
|
||||
const { ticket, oldStatus, oldUserId } = await UpdateTicketService({
|
||||
const { ticket } = await UpdateTicketService({
|
||||
ticketData,
|
||||
ticketId
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
|
||||
if (ticket.status !== oldStatus || ticket.user?.id !== oldUserId) {
|
||||
io.to(oldStatus).emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: ticket.id
|
||||
});
|
||||
}
|
||||
|
||||
io.to(ticket.status).to("notification").to(ticketId).emit("ticket", {
|
||||
action: "update",
|
||||
ticket
|
||||
});
|
||||
|
||||
return res.status(200).json(ticket);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getIO } from "../libs/socket";
|
||||
import Ticket from "../models/Ticket";
|
||||
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||
|
||||
@@ -8,23 +7,10 @@ const UpdateDeletedUserOpenTicketsStatus = async (
|
||||
tickets.forEach(async t => {
|
||||
const ticketId = t.id.toString();
|
||||
|
||||
const { ticket, oldStatus } = await UpdateTicketService({
|
||||
await UpdateTicketService({
|
||||
ticketData: { status: "pending" },
|
||||
ticketId
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
if (ticket.status !== oldStatus) {
|
||||
io.to(oldStatus).emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: ticket.id
|
||||
});
|
||||
}
|
||||
|
||||
io.to(ticket.status).to(ticketId).emit("ticket", {
|
||||
action: "updateStatus",
|
||||
ticket
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import CheckContactOpenTickets from "../../helpers/CheckContactOpenTickets";
|
||||
import SetTicketMessagesAsRead from "../../helpers/SetTicketMessagesAsRead";
|
||||
import { getIO } from "../../libs/socket";
|
||||
import Ticket from "../../models/Ticket";
|
||||
import ShowTicketService from "./ShowTicketService";
|
||||
|
||||
interface TicketData {
|
||||
status?: string;
|
||||
userId?: number;
|
||||
queueId?: number;
|
||||
}
|
||||
|
||||
interface Request {
|
||||
ticketData: TicketData;
|
||||
ticketId: string;
|
||||
ticketId: string | number;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
@@ -23,7 +25,7 @@ const UpdateTicketService = async ({
|
||||
ticketData,
|
||||
ticketId
|
||||
}: Request): Promise<Response> => {
|
||||
const { status, userId } = ticketData;
|
||||
const { status, userId, queueId } = ticketData;
|
||||
|
||||
const ticket = await ShowTicketService(ticketId);
|
||||
|
||||
@@ -38,11 +40,29 @@ const UpdateTicketService = async ({
|
||||
|
||||
await ticket.update({
|
||||
status,
|
||||
queueId,
|
||||
userId
|
||||
});
|
||||
|
||||
await ticket.reload();
|
||||
|
||||
const io = getIO();
|
||||
|
||||
if (ticket.status !== oldStatus || ticket.user?.id !== oldUserId) {
|
||||
io.to(oldStatus).emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: ticket.id
|
||||
});
|
||||
}
|
||||
|
||||
io.to(ticket.status)
|
||||
.to("notification")
|
||||
.to(ticketId.toString())
|
||||
.emit("ticket", {
|
||||
action: "update",
|
||||
ticket
|
||||
});
|
||||
|
||||
return { ticket, oldStatus, oldUserId };
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import CreateOrUpdateContactService from "../ContactServices/CreateOrUpdateConta
|
||||
import FindOrCreateTicketService from "../TicketServices/FindOrCreateTicketService";
|
||||
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
|
||||
import { debounce } from "../../helpers/Debounce";
|
||||
import UpdateTicketService from "../TicketServices/UpdateTicketService";
|
||||
|
||||
interface Session extends Client {
|
||||
id?: number;
|
||||
@@ -137,8 +138,11 @@ const verifyQueue = async (
|
||||
const { queues, greetingMessage } = await ShowWhatsAppService(wbot.id!);
|
||||
|
||||
if (queues.length === 1) {
|
||||
await ticket.$set("queue", queues[0]);
|
||||
// TODO sendTicketQueueUpdate to frontend
|
||||
// await ticket.$set("queue", queues[0].id);
|
||||
await UpdateTicketService({
|
||||
ticketData: { queueId: queues[0].id },
|
||||
ticketId: ticket.id
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -148,15 +152,16 @@ const verifyQueue = async (
|
||||
const choosenQueue = queues[+selectedOption - 1];
|
||||
|
||||
if (choosenQueue) {
|
||||
await ticket.$set("queue", choosenQueue);
|
||||
await UpdateTicketService({
|
||||
ticketData: { queueId: choosenQueue.id },
|
||||
ticketId: ticket.id
|
||||
});
|
||||
|
||||
const body = `\u200e${choosenQueue.greetingMessage}`;
|
||||
|
||||
const sentMessage = await wbot.sendMessage(`${contact.number}@c.us`, body);
|
||||
|
||||
await verifyMessage(sentMessage, ticket, contact);
|
||||
|
||||
// TODO sendTicketQueueUpdate to frontend
|
||||
} else {
|
||||
let options = "";
|
||||
|
||||
|
||||
@@ -187,6 +187,9 @@ const TicketsList = ({ status, searchParam, showAll, selectedQueueIds }) => {
|
||||
(!ticket.userId || ticket.userId === user?.id || showAll) &&
|
||||
(!ticket.queueId || selectedQueueIds.indexOf(ticket.queueId) > -1);
|
||||
|
||||
const notBelongsToUserQueues = ticket =>
|
||||
selectedQueueIds.indexOf(ticket.queueId) === -1;
|
||||
|
||||
socket.on("connect", () => {
|
||||
if (status) {
|
||||
socket.emit("joinTickets", status);
|
||||
@@ -210,6 +213,10 @@ const TicketsList = ({ status, searchParam, showAll, selectedQueueIds }) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (data.action === "update" && notBelongsToUserQueues(data.ticket)) {
|
||||
dispatch({ type: "DELETE_TICKET", payload: data.ticket.id });
|
||||
}
|
||||
|
||||
if (data.action === "delete") {
|
||||
dispatch({ type: "DELETE_TICKET", payload: data.ticketId });
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ export function useLocalStorage(key, initialValue) {
|
||||
});
|
||||
|
||||
const setValue = value => {
|
||||
console.log("SETTING VALUE", value);
|
||||
try {
|
||||
const valueToStore =
|
||||
value instanceof Function ? value(storedValue) : value;
|
||||
|
||||
Reference in New Issue
Block a user