fix(ticket-list): added an order by reflecting the business needs

This commit is contained in:
Matthieu Haineault 2026-03-02 13:07:11 -05:00
parent f43d3ade19
commit 9efe1aded7

View File

@ -25,7 +25,9 @@ export class GetTicketListService {
where: { email }, where: { email },
}); });
if (!staff) return { success: false, error: 'EMPLOYEE_NOT_FOUND' } if (!staff) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }
if (!sortOrders.includes(sortOrder) || !sortTypes.includes(sortType)) return { success: false, error: 'INVALID_FILTER' } if (!sortOrders.includes(sortOrder) || !sortTypes.includes(sortType)) {
return { success: false, error: 'INVALID_FILTER' }
}
const statusList = Prisma.join(status); const statusList = Prisma.join(status);
@ -58,9 +60,17 @@ export class GetTicketListService {
LEFT JOIN ticket t ON t.assign_to = s.id LEFT JOIN ticket t ON t.assign_to = s.id
LEFT JOIN account a ON t.account_id = a.id LEFT JOIN account a ON t.account_id = a.id
LEFT JOIN ticket_dept d ON t.dept_id = d.id LEFT JOIN ticket_dept d ON t.dept_id = d.id
WHERE s.id = ${staff.id}
AND t.status IN (${statusList}) WHERE t.status IN (${statusList})
ORDER BY ${Prisma.raw(sortOrder)} ${Prisma.raw(sortType)} ORDER BY ${Prisma.raw(sortOrder)} ${Prisma.raw(sortType)}
CASE
WHEN t.status = 'open' AND t.assign_to = 0 THEN 0
WHEN t.status = 'open' AND t.assign_to = ${staff.id} THEN 1
WHEN t.status = 'pending' AND t.assign_to = ${staff.id} THEN 2
WHEN t.status = 'open' AND t.assign_to != ${staff.id} THEN 3
WHEN t.status = 'pending' AND t.assign_to != ${staff.id} THEN 4
ELSE 5
END
LIMIT ${limit} OFFSET ${offset} LIMIT ${limit} OFFSET ${offset}
`); `);
@ -110,15 +120,14 @@ export class GetTicketListService {
FROM staff s FROM staff s
LEFT JOIN ticket t ON t.assign_to = s.id LEFT JOIN ticket t ON t.assign_to = s.id
LEFT JOIN account a ON t.account_id = a.id LEFT JOIN account a ON t.account_id = a.id
LEFT JOIN ticket_dept d ON t.dept_id = d.id LEFT JOIN ticket_dept d ON t.dept_id = d.i
WHERE s.id = ${staff.id}
ORDER BY ORDER BY
CASE CASE
WHEN t.status = 'open' AND t.assign_to = 0 THEN 0 WHEN t.status = 'open' AND t.assign_to = 0 THEN 0
WHEN t.status = 'open' AND t.assign_to = s.id THEN 1 WHEN t.status = 'open' AND t.assign_to = ${staff.id} THEN 1
WHEN t.status = 'pending' AND t.assign_to = s.id THEN 2 WHEN t.status = 'pending' AND t.assign_to = ${staff.id} THEN 2
WHEN t.status = 'open' AND t.assign_to != s.id THEN 3 WHEN t.status = 'open' AND t.assign_to != ${staff.id} THEN 3
WHEN t.status = 'pending' AND t.assign_to != s.id THEN 4 WHEN t.status = 'pending' AND t.assign_to != ${staff.id} THEN 4
ELSE 5 ELSE 5
END END
LIMIT ${limit} OFFSET ${offset}; LIMIT ${limit} OFFSET ${offset};