mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 11:49:19 +00:00
improvement: remove tickets logic from useTickets to improve notifications
This commit is contained in:
@@ -66,7 +66,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
io.to(ticketId).to("notification").emit("appMessage", {
|
||||
io.to(ticketId).to("notification").to(ticket.status).emit("appMessage", {
|
||||
action: "create",
|
||||
message,
|
||||
ticket,
|
||||
|
||||
@@ -18,6 +18,7 @@ type IndexQuery = {
|
||||
interface TicketData {
|
||||
contactId: number;
|
||||
status: string;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
@@ -46,12 +47,12 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
};
|
||||
|
||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||
const { contactId, status }: TicketData = req.body;
|
||||
const { contactId, status, userId }: TicketData = req.body;
|
||||
|
||||
const ticket = await CreateTicketService({ contactId, status });
|
||||
const ticket = await CreateTicketService({ contactId, status, userId });
|
||||
|
||||
const io = getIO();
|
||||
io.to("notification").emit("ticket", {
|
||||
io.to(ticket.status).emit("ticket", {
|
||||
action: "create",
|
||||
ticket
|
||||
});
|
||||
@@ -66,10 +67,21 @@ export const update = async (
|
||||
const { ticketId } = req.params;
|
||||
const ticketData: TicketData = req.body;
|
||||
|
||||
const ticket = await UpdateTicketService({ ticketData, ticketId });
|
||||
const { ticket, oldStatus } = await UpdateTicketService({
|
||||
ticketData,
|
||||
ticketId
|
||||
});
|
||||
|
||||
const io = getIO();
|
||||
io.to("notification").emit("ticket", {
|
||||
|
||||
if (ticket.status !== oldStatus) {
|
||||
io.to(oldStatus).emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: ticket.id
|
||||
});
|
||||
}
|
||||
|
||||
io.to(ticket.status).emit("ticket", {
|
||||
action: "updateStatus",
|
||||
ticket
|
||||
});
|
||||
@@ -83,13 +95,15 @@ export const remove = async (
|
||||
): Promise<Response> => {
|
||||
const { ticketId } = req.params;
|
||||
|
||||
await DeleteTicketService(ticketId);
|
||||
const ticket = await DeleteTicketService(ticketId);
|
||||
|
||||
const io = getIO();
|
||||
io.to("notification").emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: +ticketId
|
||||
});
|
||||
io.to(ticket.status)
|
||||
.to("notification")
|
||||
.emit("ticket", {
|
||||
action: "delete",
|
||||
ticketId: +ticketId
|
||||
});
|
||||
|
||||
return res.status(200).json({ message: "ticket deleted" });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user