mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
improvement: moved notification logic to backend
This commit is contained in:
@@ -12,6 +12,7 @@ type IndexQuery = {
|
||||
status: string;
|
||||
date: string;
|
||||
showAll: string;
|
||||
withUnreadMessages: string;
|
||||
};
|
||||
|
||||
interface TicketData {
|
||||
@@ -25,7 +26,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
status,
|
||||
date,
|
||||
searchParam,
|
||||
showAll
|
||||
showAll,
|
||||
withUnreadMessages
|
||||
} = req.query as IndexQuery;
|
||||
|
||||
const userId = req.user.id;
|
||||
@@ -36,7 +38,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
userId
|
||||
userId,
|
||||
withUnreadMessages
|
||||
});
|
||||
|
||||
return res.status(200).json({ tickets, count, hasMore });
|
||||
|
||||
@@ -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