mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 03:39:29 +00:00
fix: tickets not disappearing for users that are not members of queue after queue assignment
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user