fix(ticket-list): added an order by reflecting the business needs
This commit is contained in:
parent
f43d3ade19
commit
9efe1aded7
|
|
@ -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,16 +120,15 @@ 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};
|
||||||
`);
|
`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user