diff --git a/backend/src/models/Ticket.js b/backend/src/models/Ticket.js index a2c1619..7024fd6 100644 --- a/backend/src/models/Ticket.js +++ b/backend/src/models/Ticket.js @@ -15,6 +15,18 @@ class Ticket extends Sequelize.Model { } ); + this.addHook("afterFind", async result => { + if (result.length > 0) { + await Promise.all( + result.map(async ticket => { + ticket.unreadMessages = await Message.count({ + where: { ticketId: ticket.id, read: false }, + }); + }) + ); + } + }); + this.addHook("afterUpdate", async ticket => { ticket.unreadMessages = await Message.count({ where: { ticketId: ticket.id, read: false }, diff --git a/frontend/src/components/TicketsList/index.js b/frontend/src/components/TicketsList/index.js index b89b26f..e8b4823 100644 --- a/frontend/src/components/TicketsList/index.js +++ b/frontend/src/components/TicketsList/index.js @@ -251,7 +251,6 @@ const TicketsList = () => { socket.emit("joinNotification"); socket.on("ticket", data => { - console.log("data", data); if (data.action === "updateUnread") { resetUnreadMessages(data); } @@ -287,7 +286,6 @@ const TicketsList = () => { }, [ticketId, userId, history]); const updateTickets = ({ ticket }) => { - console.log("recebido", ticket); setTickets(prevState => { const ticketIndex = prevState.findIndex(t => t.id === ticket.id); @@ -302,8 +300,6 @@ const TicketsList = () => { }); }; - console.log(tickets); - const deleteTicket = ({ ticketId }) => { setTickets(prevState => { const ticketIndex = prevState.findIndex(ticket => ticket.id === ticketId);