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(`
|
postgresClient.query(`
|
||||||
SELECT t.status, COUNT(*) as count
|
SELECT t.status, COUNT(*) as count
|
||||||
FROM tickets t
|
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
|
WHERE t.status != 5 AND t.is_deleted = false
|
||||||
GROUP BY t.status ORDER BY count DESC
|
GROUP BY t.status ORDER BY count DESC
|
||||||
`),
|
`),
|
||||||
postgresClient.query(`
|
postgresClient.query(`
|
||||||
SELECT t.queue_id, q.label as queue_label, COUNT(*) as count
|
SELECT t.queue_id, q.label as queue_label, COUNT(*) as count
|
||||||
FROM tickets t
|
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
|
LEFT JOIN queues q ON q.value = t.queue_id
|
||||||
WHERE t.status != 5 AND t.is_deleted = false
|
WHERE t.status != 5 AND t.is_deleted = false
|
||||||
GROUP BY t.queue_id, q.label ORDER BY count DESC LIMIT 8
|
GROUP BY t.queue_id, q.label ORDER BY count DESC LIMIT 8
|
||||||
|
|
@ -19,6 +21,7 @@ export async function GET() {
|
||||||
postgresClient.query(`
|
postgresClient.query(`
|
||||||
SELECT t.priority, p.label, COUNT(*) as count
|
SELECT t.priority, p.label, COUNT(*) as count
|
||||||
FROM tickets t
|
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
|
LEFT JOIN priorities p ON p.value = t.priority
|
||||||
WHERE t.status != 5 AND t.is_deleted = false
|
WHERE t.status != 5 AND t.is_deleted = false
|
||||||
GROUP BY t.priority, p.label ORDER BY count DESC
|
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,
|
c.company_name, q.label as queue_label,
|
||||||
r.first_name || ' ' || r.last_name as assigned_to
|
r.first_name || ' ' || r.last_name as assigned_to
|
||||||
FROM tickets t
|
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 queues q ON q.value = t.queue_id
|
||||||
LEFT JOIN resources r ON r.id = t.assigned_resource_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
|
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(`
|
postgresClient.query(`
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) FILTER (WHERE first_response_date_time IS NOT NULL
|
COUNT(*) FILTER (WHERE t.first_response_date_time IS NOT NULL
|
||||||
AND EXTRACT(EPOCH FROM (first_response_date_time - create_date))/3600 <= 1) as resp_met,
|
AND EXTRACT(EPOCH FROM (t.first_response_date_time - t.create_date))/3600 <= 1) as resp_met,
|
||||||
COUNT(*) FILTER (WHERE first_response_date_time IS NOT NULL) as resp_total,
|
COUNT(*) FILTER (WHERE t.first_response_date_time IS NOT NULL) as resp_total,
|
||||||
COUNT(*) FILTER (WHERE resolved_date_time IS NOT NULL
|
COUNT(*) FILTER (WHERE t.resolved_date_time IS NOT NULL
|
||||||
AND EXTRACT(EPOCH FROM (resolved_date_time - create_date))/3600 <= 24) as res_met,
|
AND EXTRACT(EPOCH FROM (t.resolved_date_time - t.create_date))/3600 <= 24) as res_met,
|
||||||
COUNT(*) FILTER (WHERE resolved_date_time IS NOT NULL) as res_total
|
COUNT(*) FILTER (WHERE t.resolved_date_time IS NOT NULL) as res_total
|
||||||
FROM tickets
|
FROM tickets t
|
||||||
WHERE create_date >= NOW() - INTERVAL '30 days' AND is_deleted = false
|
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 limit = 30;
|
||||||
const offset = (page - 1) * limit;
|
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[] = [];
|
const params: unknown[] = [];
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
|
|
@ -36,7 +40,7 @@ export async function GET(request: NextRequest) {
|
||||||
c.company_name,
|
c.company_name,
|
||||||
r.first_name || ' ' || r.last_name as assigned_to
|
r.first_name || ' ' || r.last_name as assigned_to
|
||||||
FROM tickets t
|
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 queues q ON q.value = t.queue_id
|
||||||
LEFT JOIN resources r ON r.id = t.assigned_resource_id
|
LEFT JOIN resources r ON r.id = t.assigned_resource_id
|
||||||
WHERE ${where}
|
WHERE ${where}
|
||||||
|
|
@ -46,7 +50,7 @@ export async function GET(request: NextRequest) {
|
||||||
postgresClient.query(`
|
postgresClient.query(`
|
||||||
SELECT COUNT(*) as total
|
SELECT COUNT(*) as total
|
||||||
FROM tickets t
|
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}
|
WHERE ${where}
|
||||||
`, params),
|
`, params),
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue