mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
code cleanup
This commit is contained in:
@@ -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 => {
|
this.addHook("afterUpdate", async ticket => {
|
||||||
ticket.unreadMessages = await Message.count({
|
ticket.unreadMessages = await Message.count({
|
||||||
where: { ticketId: ticket.id, read: false },
|
where: { ticketId: ticket.id, read: false },
|
||||||
|
|||||||
@@ -251,7 +251,6 @@ const TicketsList = () => {
|
|||||||
socket.emit("joinNotification");
|
socket.emit("joinNotification");
|
||||||
|
|
||||||
socket.on("ticket", data => {
|
socket.on("ticket", data => {
|
||||||
console.log("data", data);
|
|
||||||
if (data.action === "updateUnread") {
|
if (data.action === "updateUnread") {
|
||||||
resetUnreadMessages(data);
|
resetUnreadMessages(data);
|
||||||
}
|
}
|
||||||
@@ -287,7 +286,6 @@ const TicketsList = () => {
|
|||||||
}, [ticketId, userId, history]);
|
}, [ticketId, userId, history]);
|
||||||
|
|
||||||
const updateTickets = ({ ticket }) => {
|
const updateTickets = ({ ticket }) => {
|
||||||
console.log("recebido", ticket);
|
|
||||||
setTickets(prevState => {
|
setTickets(prevState => {
|
||||||
const ticketIndex = prevState.findIndex(t => t.id === ticket.id);
|
const ticketIndex = prevState.findIndex(t => t.id === ticket.id);
|
||||||
|
|
||||||
@@ -302,8 +300,6 @@ const TicketsList = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(tickets);
|
|
||||||
|
|
||||||
const deleteTicket = ({ ticketId }) => {
|
const deleteTicket = ({ ticketId }) => {
|
||||||
setTickets(prevState => {
|
setTickets(prevState => {
|
||||||
const ticketIndex = prevState.findIndex(ticket => ticket.id === ticketId);
|
const ticketIndex = prevState.findIndex(ticket => ticket.id === ticketId);
|
||||||
|
|||||||
Reference in New Issue
Block a user