From db9dae7c7c6173469877beda0ffc6e3bb574c81d Mon Sep 17 00:00:00 2001 From: lorentz Date: Tue, 14 Apr 2026 00:36:17 +0000 Subject: [PATCH] Scope dashboard KPIs to Shape clients only - Client count: Shape/Shape2 designation only - Policy count: active Shape policies (excludes dead statuses) - Task count: open tasks on Shape clients (excludes NA/CANCELLED) - Completion rate: excludes NA/CANCELLED from denominator - /api/metrics intentionally left as system-wide (Prometheus) --- ondeck/src/app/(dashboard)/dashboard/page.tsx | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ondeck/src/app/(dashboard)/dashboard/page.tsx b/ondeck/src/app/(dashboard)/dashboard/page.tsx index 32b9a9a..170b0a4 100644 --- a/ondeck/src/app/(dashboard)/dashboard/page.tsx +++ b/ondeck/src/app/(dashboard)/dashboard/page.tsx @@ -14,15 +14,18 @@ export default async function DashboardPage() { redirect('/auth/signin') } - // Fetch real statistics - const [clientCount, policyCount, taskCount] = await Promise.all([ - prisma.client.count(), - prisma.policy.count(), - prisma.task.count({ where: { status: { not: 'COMPLETED' } } }), + // Fetch real statistics — scoped to Shape clients only + const shapeWhere = { designation: { name: { in: ['Shape', 'Shape 2'] } } } + const shapeClientIds = (await prisma.client.findMany({ where: shapeWhere, select: { id: true } })).map((c) => c.id) + + const [clientCount, policyCount, taskCount, completedTasks, totalTasks] = await Promise.all([ + prisma.client.count({ where: shapeWhere }), + prisma.policy.count({ where: { clientId: { in: shapeClientIds }, status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } } }), + prisma.task.count({ where: { clientId: { in: shapeClientIds }, status: { notIn: ['COMPLETED', 'CANCELLED', 'NA'] } } }), + prisma.task.count({ where: { clientId: { in: shapeClientIds }, status: 'COMPLETED' } }), + prisma.task.count({ where: { clientId: { in: shapeClientIds }, status: { notIn: ['CANCELLED', 'NA'] } } }), ]) - const completedTasks = await prisma.task.count({ where: { status: 'COMPLETED' } }) - const totalTasks = await prisma.task.count() const completionRate = totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0 return ( @@ -47,7 +50,7 @@ export default async function DashboardPage() {
{clientCount}

- Active client accounts + Shape program clients

@@ -60,7 +63,7 @@ export default async function DashboardPage() {
{policyCount}

- Policies requiring renewal + Active Shape policies

@@ -73,7 +76,7 @@ export default async function DashboardPage() {
{taskCount}

- Tasks awaiting completion + Open tasks (excludes NA/cancelled)

@@ -86,7 +89,7 @@ export default async function DashboardPage() {
{completionRate}%

- Tasks completed on time + Tasks completed vs total