From b1b0dfa64d60b5e8b82e3f29654c38e8d4744005 Mon Sep 17 00:00:00 2001 From: lorentz Date: Tue, 2 Jun 2026 00:01:01 +0000 Subject: [PATCH] Fix: align task visibility filters across all API routes and dashboards - api/tasks/route.ts: fix group-expiry filter to never hide open tasks; replace dueDate-based age filter with completedAt-based filter so open tasks are always visible regardless of how old they are - api/dashboard/workload/route.ts: add dead-policy exclusion to base task filter so overdue counts and per-user workload rows exclude tasks on cancelled/expired/non-renewed policies - manager/page.tsx: same dead-policy exclusion on teamMembers task query - api/metrics/route.ts: fix horizon_tasks_overdue to exclude dead-policy tasks --- ondeck/src/app/(dashboard)/manager/page.tsx | 1 + ondeck/src/app/api/dashboard/workload/route.ts | 5 ++++- ondeck/src/app/api/metrics/route.ts | 2 +- ondeck/src/app/api/tasks/route.ts | 14 ++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ondeck/src/app/(dashboard)/manager/page.tsx b/ondeck/src/app/(dashboard)/manager/page.tsx index 1110f1c..87088d9 100644 --- a/ondeck/src/app/(dashboard)/manager/page.tsx +++ b/ondeck/src/app/(dashboard)/manager/page.tsx @@ -56,6 +56,7 @@ export default async function ManagerPage() { task: { clientId: { in: shapeClientIds }, status: { notIn: ['COMPLETED', 'CANCELLED', 'NA'] }, + NOT: { policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } } }, } }, select: { diff --git a/ondeck/src/app/api/dashboard/workload/route.ts b/ondeck/src/app/api/dashboard/workload/route.ts index 0098ca9..a8b0033 100644 --- a/ondeck/src/app/api/dashboard/workload/route.ts +++ b/ondeck/src/app/api/dashboard/workload/route.ts @@ -30,9 +30,12 @@ export async function GET(request: NextRequest) { }) const shapeClientIds = shapeClients.map((c) => c.id) - // Base task filter — scoped to Shape clients only + const DEAD_POLICY_STATUSES = ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] + + // Base task filter — scoped to Shape clients only, excluding dead policies const deptTaskWhere = { clientId: { in: shapeClientIds }, + NOT: { policy: { status: { in: DEAD_POLICY_STATUSES } } }, ...(departmentFilter ? { department: departmentFilter.toUpperCase() as DepartmentType } : {}), } diff --git a/ondeck/src/app/api/metrics/route.ts b/ondeck/src/app/api/metrics/route.ts index 86a55e1..a726658 100644 --- a/ondeck/src/app/api/metrics/route.ts +++ b/ondeck/src/app/api/metrics/route.ts @@ -60,7 +60,7 @@ export async function GET(request: NextRequest) { prisma.task.count(), prisma.task.groupBy({ by: ['status'], _count: { id: true } }), prisma.task.groupBy({ by: ['department'], _count: { id: true } }), - prisma.task.count({ where: { dueDate: { lt: now }, status: { notIn: ['COMPLETED', 'NA', 'CANCELLED'] } } }), + prisma.task.count({ where: { dueDate: { lt: now }, status: { notIn: ['COMPLETED', 'NA', 'CANCELLED'] }, NOT: { policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } } } } }), prisma.task.count({ where: { createdAt: { gte: todayStart } } }), prisma.task.count({ where: { completedAt: { gte: todayStart } } }), prisma.task.count({ where: { createdAt: { gte: weekAgo } } }), diff --git a/ondeck/src/app/api/tasks/route.ts b/ondeck/src/app/api/tasks/route.ts index e3a6403..be2f3b9 100644 --- a/ondeck/src/app/api/tasks/route.ts +++ b/ondeck/src/app/api/tasks/route.ts @@ -36,18 +36,24 @@ export async function GET(request: NextRequest) { policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } }, }, }, - // Exclude tasks on expired renewal groups + // Exclude tasks on expired renewal groups — but NEVER hide open tasks { OR: [ { policyGroupId: null }, { policyGroup: { renewalDate: { gte: cutoff } } }, + { status: { notIn: ['COMPLETED', 'CANCELLED', 'NA'] } }, ], }, - // Exclude old non-terminal tasks + // Keep ALL open tasks regardless of age; only show terminal tasks completed/closed recently { OR: [ - { dueDate: { gte: cutoff } }, - { status: { in: ['COMPLETED', 'CANCELLED', 'NA'] } }, + { status: { notIn: ['COMPLETED', 'CANCELLED', 'NA'] } }, + { + AND: [ + { status: { in: ['COMPLETED', 'CANCELLED', 'NA'] } }, + { completedAt: { gte: cutoff } }, + ], + }, ], }, ]