feat: mobile — filter all queries to Wulf Managed companies only
All mobile dashboard and ticket list queries now INNER JOIN companies on user_defined_fields->>'MSP Service Model' = 'Wulf Managed', scoping all stats (open total, by priority, by queue, SLA, recent activity) and ticket list to managed clients only. 349 open tickets in scope.
This commit is contained in:
parent
012c7bde50
commit
fe9f806c50
2 changed files with 20 additions and 12 deletions
|
|
@ -6,12 +6,14 @@ export async function GET() {
|
|||
postgresClient.query(`
|
||||
SELECT t.status, COUNT(*) as count
|
||||
FROM tickets t
|
||||
INNER JOIN companies c ON c.id = t.company_id AND c.user_defined_fields->>'MSP Service Model' = 'Wulf Managed'
|
||||
WHERE t.status != 5 AND t.is_deleted = false
|
||||
GROUP BY t.status ORDER BY count DESC
|
||||
`),
|
||||
postgresClient.query(`
|
||||
SELECT t.queue_id, q.label as queue_label, COUNT(*) as count
|
||||
FROM tickets t
|
||||
INNER JOIN companies c ON c.id = t.company_id AND c.user_defined_fields->>'MSP Service Model' = 'Wulf Managed'
|
||||
LEFT JOIN queues q ON q.value = t.queue_id
|
||||
WHERE t.status != 5 AND t.is_deleted = false
|
||||
GROUP BY t.queue_id, q.label ORDER BY count DESC LIMIT 8
|
||||
|
|
@ -19,6 +21,7 @@ export async function GET() {
|
|||
postgresClient.query(`
|
||||
SELECT t.priority, p.label, COUNT(*) as count
|
||||
FROM tickets t
|
||||
INNER JOIN companies c ON c.id = t.company_id AND c.user_defined_fields->>'MSP Service Model' = 'Wulf Managed'
|
||||
LEFT JOIN priorities p ON p.value = t.priority
|
||||
WHERE t.status != 5 AND t.is_deleted = false
|
||||
GROUP BY t.priority, p.label ORDER BY count DESC
|
||||
|
|
@ -29,7 +32,7 @@ export async function GET() {
|
|||
c.company_name, q.label as queue_label,
|
||||
r.first_name || ' ' || r.last_name as assigned_to
|
||||
FROM tickets t
|
||||
LEFT JOIN companies c ON c.id = t.company_id
|
||||
INNER JOIN companies c ON c.id = t.company_id AND c.user_defined_fields->>'MSP Service Model' = 'Wulf Managed'
|
||||
LEFT JOIN queues q ON q.value = t.queue_id
|
||||
LEFT JOIN resources r ON r.id = t.assigned_resource_id
|
||||
WHERE t.status != 5 AND t.is_deleted = false AND t.last_activity_date IS NOT NULL
|
||||
|
|
@ -37,14 +40,15 @@ export async function GET() {
|
|||
`),
|
||||
postgresClient.query(`
|
||||
SELECT
|
||||
COUNT(*) FILTER (WHERE first_response_date_time IS NOT NULL
|
||||
AND EXTRACT(EPOCH FROM (first_response_date_time - create_date))/3600 <= 1) as resp_met,
|
||||
COUNT(*) FILTER (WHERE first_response_date_time IS NOT NULL) as resp_total,
|
||||
COUNT(*) FILTER (WHERE resolved_date_time IS NOT NULL
|
||||
AND EXTRACT(EPOCH FROM (resolved_date_time - create_date))/3600 <= 24) as res_met,
|
||||
COUNT(*) FILTER (WHERE resolved_date_time IS NOT NULL) as res_total
|
||||
FROM tickets
|
||||
WHERE create_date >= NOW() - INTERVAL '30 days' AND is_deleted = false
|
||||
COUNT(*) FILTER (WHERE t.first_response_date_time IS NOT NULL
|
||||
AND EXTRACT(EPOCH FROM (t.first_response_date_time - t.create_date))/3600 <= 1) as resp_met,
|
||||
COUNT(*) FILTER (WHERE t.first_response_date_time IS NOT NULL) as resp_total,
|
||||
COUNT(*) FILTER (WHERE t.resolved_date_time IS NOT NULL
|
||||
AND EXTRACT(EPOCH FROM (t.resolved_date_time - t.create_date))/3600 <= 24) as res_met,
|
||||
COUNT(*) FILTER (WHERE t.resolved_date_time IS NOT NULL) as res_total
|
||||
FROM tickets t
|
||||
INNER JOIN companies c ON c.id = t.company_id AND c.user_defined_fields->>'MSP Service Model' = 'Wulf Managed'
|
||||
WHERE t.create_date >= NOW() - INTERVAL '30 days' AND t.is_deleted = false
|
||||
`),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,11 @@ export async function GET(request: NextRequest) {
|
|||
const limit = 30;
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
const conditions: string[] = ['t.status != 5', 't.is_deleted = false'];
|
||||
const conditions: string[] = [
|
||||
't.status != 5',
|
||||
't.is_deleted = false',
|
||||
"c.user_defined_fields->>'MSP Service Model' = 'Wulf Managed'",
|
||||
];
|
||||
const params: unknown[] = [];
|
||||
|
||||
if (search) {
|
||||
|
|
@ -36,7 +40,7 @@ export async function GET(request: NextRequest) {
|
|||
c.company_name,
|
||||
r.first_name || ' ' || r.last_name as assigned_to
|
||||
FROM tickets t
|
||||
LEFT JOIN companies c ON c.id = t.company_id
|
||||
INNER JOIN companies c ON c.id = t.company_id
|
||||
LEFT JOIN queues q ON q.value = t.queue_id
|
||||
LEFT JOIN resources r ON r.id = t.assigned_resource_id
|
||||
WHERE ${where}
|
||||
|
|
@ -46,7 +50,7 @@ export async function GET(request: NextRequest) {
|
|||
postgresClient.query(`
|
||||
SELECT COUNT(*) as total
|
||||
FROM tickets t
|
||||
LEFT JOIN companies c ON c.id = t.company_id
|
||||
INNER JOIN companies c ON c.id = t.company_id
|
||||
WHERE ${where}
|
||||
`, params),
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue