improvement: moved unreadMessages logic to model

This commit is contained in:
canove
2020-08-04 11:18:26 -03:00
parent 7a99abe543
commit 0b61e8391f
4 changed files with 17 additions and 55 deletions

View File

@@ -39,22 +39,6 @@ exports.index = async (req, res) => {
attributes: ["name", "number", "profilePicUrl"],
},
],
attributes: {
include: [
[
Sequelize.literal(`(
SELECT COUNT(*)
FROM Messages AS message
WHERE
message.ticketId = Ticket.id
AND
message.read = 0
)`),
"unreadMessages",
],
],
},
order: [["updatedAt", "DESC"]],
});
@@ -89,22 +73,6 @@ exports.update = async (req, res) => {
attributes: ["name", "number", "profilePicUrl"],
},
],
attributes: {
include: [
[
Sequelize.literal(`(
SELECT COUNT(*)
FROM Messages AS message
WHERE
message.ticketId = Ticket.id
AND
message.read = 0
)`),
"unreadMessages",
],
],
},
});
if (!ticket) {