code cleanup

This commit is contained in:
canove
2020-08-04 11:41:25 -03:00
parent 0b61e8391f
commit 5848359075
2 changed files with 12 additions and 4 deletions

View File

@@ -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 },

View File

@@ -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);