mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 20:29:17 +00:00
before remove infinity scrol
This commit is contained in:
@@ -3,6 +3,7 @@ const Message = require("../models/Message");
|
||||
const Contact = require("../models/Contact");
|
||||
const { getIO } = require("../socket");
|
||||
const { getWbot } = require("./wbot");
|
||||
const sequelize = require("sequelize");
|
||||
|
||||
const { MessageMedia } = require("whatsapp-web.js");
|
||||
|
||||
@@ -35,10 +36,20 @@ exports.getContactMessages = async (req, res, next) => {
|
||||
const io = getIO();
|
||||
|
||||
const { contactId } = req.params;
|
||||
const { search, page = 1 } = req.query;
|
||||
const { searchParam, pageNumber = 1 } = req.query;
|
||||
|
||||
let limit = 5;
|
||||
let offset = limit * (page - 1);
|
||||
const lowerSerachParam = searchParam.toLowerCase();
|
||||
|
||||
const whereCondition = {
|
||||
messageBody: sequelize.where(
|
||||
sequelize.fn("LOWER", sequelize.col("messageBody")),
|
||||
"LIKE",
|
||||
"%" + lowerSerachParam + "%"
|
||||
),
|
||||
};
|
||||
|
||||
let limit = 10;
|
||||
let offset = limit * (pageNumber - 1);
|
||||
|
||||
try {
|
||||
const contact = await Contact.findByPk(contactId);
|
||||
@@ -50,13 +61,17 @@ exports.getContactMessages = async (req, res, next) => {
|
||||
|
||||
setMessagesAsRead(contactId);
|
||||
|
||||
const messagesFound = await contact.countMessages({
|
||||
where: whereCondition,
|
||||
});
|
||||
const contactMessages = await contact.getMessages({
|
||||
where: whereCondition,
|
||||
limit,
|
||||
offset,
|
||||
order: [["createdAt", "DESC"]],
|
||||
});
|
||||
|
||||
return res.json(contactMessages.reverse());
|
||||
return res.json({ messages: contactMessages.reverse(), messagesFound });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"WABrowserId":"\"W5pw0Llb60mSeV7WOHnk8A==\"","WASecretBundle":"{\"key\":\"alDLbPjonDFzCh5PEPql9cy59LNh1HFG/AZJVoucuYI=\",\"encKey\":\"FQ1MZ2eIH9hKV4dqFoBYTv1/89aopcMAa4CXgh/9csM=\",\"macKey\":\"alDLbPjonDFzCh5PEPql9cy59LNh1HFG/AZJVoucuYI=\"}","WAToken1":"\"GvHbBS6HkZD8f5nYpOxt5qsna4XaDx3JPsjoxwKiM6g=\"","WAToken2":"\"1@P1h9eDyW0m0ILzNfgs6sEF35E66OndfdlOjm3oYzeV13cg82FjBbRvhsma9+p5+/R7zjMUv6L+l/gg==\""}
|
||||
{"WABrowserId":"\"W5pw0Llb60mSeV7WOHnk8A==\"","WASecretBundle":"{\"key\":\"alDLbPjonDFzCh5PEPql9cy59LNh1HFG/AZJVoucuYI=\",\"encKey\":\"FQ1MZ2eIH9hKV4dqFoBYTv1/89aopcMAa4CXgh/9csM=\",\"macKey\":\"alDLbPjonDFzCh5PEPql9cy59LNh1HFG/AZJVoucuYI=\"}","WAToken1":"\"SNPReadfNoQL/i4IzN6BWtMxFsAkB5S1rvYwNsEywWs=\"","WAToken2":"\"1@6K32SNdV0LtNeieRuXYWmwUaGMsC18JBxEIlraW3rBgxeZ4DbiD2WtYs1Ekv/QO5RDPieBfHuWzZPw==\""}
|
||||
Reference in New Issue
Block a user