feat: add queue filter to tickets list

This commit is contained in:
canove
2021-01-13 12:22:43 -03:00
parent ef6291c48d
commit aac6d30083
9 changed files with 160 additions and 24 deletions

View File

@@ -14,6 +14,7 @@ type IndexQuery = {
date: string;
showAll: string;
withUnreadMessages: string;
queueIds: string;
};
interface TicketData {
@@ -29,11 +30,18 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
date,
searchParam,
showAll,
queueIds: queueIdsStringified,
withUnreadMessages
} = req.query as IndexQuery;
const userId = req.user.id;
let queueIds: number[] = [];
if (queueIdsStringified) {
queueIds = JSON.parse(queueIdsStringified);
}
const { tickets, count, hasMore } = await ListTicketsService({
searchParam,
pageNumber,
@@ -41,6 +49,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
date,
showAll,
userId,
queueIds,
withUnreadMessages
});

View File

@@ -5,6 +5,7 @@ import Ticket from "../../models/Ticket";
import Contact from "../../models/Contact";
import Message from "../../models/Message";
import Queue from "../../models/Queue";
// import ShowUserService from "../UserServices/ShowUserService";
interface Request {
searchParam?: string;
@@ -14,6 +15,7 @@ interface Request {
showAll?: string;
userId: string;
withUnreadMessages?: string;
queueIds: number[];
}
interface Response {
@@ -25,14 +27,22 @@ interface Response {
const ListTicketsService = async ({
searchParam = "",
pageNumber = "1",
queueIds,
status,
date,
showAll,
userId,
withUnreadMessages
}: Request): Promise<Response> => {
// const user = await ShowUserService(userId);
// const userQueueIds = user.queues.map(queue => queue.id);
// console.log(userQueueIds);
let whereCondition: Filterable["where"] = {
[Op.or]: [{ userId }, { status: "pending" }]
[Op.or]: [{ userId }, { status: "pending" }],
queueId: { [Op.or]: [queueIds, null] }
};
let includeCondition: Includeable[];
@@ -85,7 +95,7 @@ const ListTicketsService = async ({
[Op.or]: [
{
"$contact.name$": where(
fn("LOWER", col("name")),
fn("LOWER", col("contact.name")),
"LIKE",
`%${sanitizedSearchParam}%`
)