mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
improvement: moved notification logic to backend
This commit is contained in:
@@ -12,6 +12,7 @@ interface Request {
|
||||
date?: string;
|
||||
showAll?: string;
|
||||
userId: string;
|
||||
withUnreadMessages?: string;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
@@ -26,24 +27,24 @@ const ListTicketsService = async ({
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
userId
|
||||
userId,
|
||||
withUnreadMessages
|
||||
}: Request): Promise<Response> => {
|
||||
let whereCondition: Filterable["where"];
|
||||
let whereCondition: Filterable["where"] = {
|
||||
[Op.or]: [{ userId }, { status: "pending" }]
|
||||
};
|
||||
let includeCondition: Includeable[];
|
||||
|
||||
includeCondition = [
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["id", "name", "number", "profilePicUrl"],
|
||||
include: ["extraInfo"]
|
||||
attributes: ["id", "name", "number", "profilePicUrl"]
|
||||
}
|
||||
];
|
||||
|
||||
if (showAll === "true") {
|
||||
whereCondition = {};
|
||||
} else {
|
||||
whereCondition = { userId };
|
||||
}
|
||||
|
||||
if (status) {
|
||||
@@ -102,6 +103,21 @@ const ListTicketsService = async ({
|
||||
};
|
||||
}
|
||||
|
||||
if (withUnreadMessages === "true") {
|
||||
includeCondition = [
|
||||
...includeCondition,
|
||||
{
|
||||
model: Message,
|
||||
as: "messages",
|
||||
attributes: [],
|
||||
where: {
|
||||
read: false,
|
||||
fromMe: false
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
const limit = 20;
|
||||
const offset = limit * (+pageNumber - 1);
|
||||
|
||||
|
||||
@@ -167,8 +167,6 @@ const wbotMessageListener = (whatsapp: Whatsapp): void => {
|
||||
const io = getIO();
|
||||
|
||||
wbot.on("message_create", async msg => {
|
||||
console.log(msg.type);
|
||||
|
||||
if (!isValidMsg(msg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user