improvement: moved notification logic to backend

This commit is contained in:
canove
2020-09-24 21:00:57 -03:00
parent c58baf3470
commit c7d3807219
5 changed files with 57 additions and 42 deletions

View File

@@ -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);

View File

@@ -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;
}