mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
maintenance commit
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
const Contact = require("../models/Contact");
|
||||
const Message = require("../models/Message");
|
||||
// const io = require("../socket");
|
||||
const Sequelize = require("sequelize");
|
||||
|
||||
exports.getContacts = async (req, res) => {
|
||||
// const contacts = await Contact.findAll();
|
||||
const contacts = await Contact.findAll({
|
||||
include: {
|
||||
model: Message,
|
||||
where: {
|
||||
read: false,
|
||||
try {
|
||||
const contacts = await Contact.findAll({
|
||||
include: { model: Message, attributes: [] },
|
||||
attributes: {
|
||||
include: [
|
||||
[
|
||||
Sequelize.literal(`(
|
||||
SELECT COUNT(*)
|
||||
FROM messages AS message
|
||||
WHERE
|
||||
message.contactId = contact.id
|
||||
AND
|
||||
message.read = 0
|
||||
|
||||
)`),
|
||||
"unreadMessages",
|
||||
],
|
||||
],
|
||||
},
|
||||
required: false,
|
||||
},
|
||||
});
|
||||
order: [[Message, "createdAt", "DESC"]],
|
||||
});
|
||||
|
||||
return res.json(contacts);
|
||||
return res.json(contacts);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user