From 8db7113c0b47e1843ca2b6e568031d7e46685149 Mon Sep 17 00:00:00 2001 From: lorentz Date: Wed, 8 Apr 2026 02:16:04 +0000 Subject: [PATCH] fix: task suppression filter was not working - NOT array requires all conditions to match Prisma NOT:[condA, condB] means exclude only if BOTH match, and OR at the same level overrode the NOT entirely. Restructured to: - NOT (single object) for dead policy exclusion - OR for group expiry check (null group OR recent renewal) - AND > OR for recent-or-terminal filter Fixed in all 3 locations: tasks page, client tasks API, client detail SSR. --- .../src/app/(dashboard)/clients/[id]/page.tsx | 19 ++++++++++----- ondeck/src/app/(dashboard)/tasks/page.tsx | 22 +++++++++++++----- .../src/app/api/clients/[id]/tasks/route.ts | 23 +++++++++++-------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/ondeck/src/app/(dashboard)/clients/[id]/page.tsx b/ondeck/src/app/(dashboard)/clients/[id]/page.tsx index d480581..d9657fb 100644 --- a/ondeck/src/app/(dashboard)/clients/[id]/page.tsx +++ b/ondeck/src/app/(dashboard)/clients/[id]/page.tsx @@ -58,13 +58,20 @@ export default async function ClientDetailPage({ const cutoff = new Date() cutoff.setDate(cutoff.getDate() - 7) return { - NOT: [ - { policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } } }, - { policyGroup: { renewalDate: { lt: cutoff } } }, - ], + NOT: { + policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } }, + }, OR: [ - { dueDate: { gte: cutoff } }, - { status: { in: ['COMPLETED', 'CANCELLED', 'NA'] } }, + { policyGroupId: null }, + { policyGroup: { renewalDate: { gte: cutoff } } }, + ], + AND: [ + { + OR: [ + { dueDate: { gte: cutoff } }, + { status: { in: ['COMPLETED', 'CANCELLED', 'NA'] } }, + ], + }, ], } })(), diff --git a/ondeck/src/app/(dashboard)/tasks/page.tsx b/ondeck/src/app/(dashboard)/tasks/page.tsx index c752ad3..375f75d 100644 --- a/ondeck/src/app/(dashboard)/tasks/page.tsx +++ b/ondeck/src/app/(dashboard)/tasks/page.tsx @@ -22,13 +22,23 @@ export default async function TasksPage() { const activeTaskWhere: Prisma.TaskWhereInput = { assignments: { some: { userId } }, - NOT: [ - { policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } } } as Prisma.TaskWhereInput, - { policyGroup: { renewalDate: { lt: cutoff } } } as Prisma.TaskWhereInput, - ], + // Exclude tasks on dead policies + NOT: { + policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } }, + } as Prisma.TaskWhereInput, + // Exclude tasks on expired renewal groups OR: [ - { dueDate: { gte: cutoff } }, - { status: { in: TERMINAL_STATUSES } }, + { policyGroupId: null }, + { policyGroup: { renewalDate: { gte: cutoff } } }, + ], + // Only show recent or terminal tasks + AND: [ + { + OR: [ + { dueDate: { gte: cutoff } }, + { status: { in: TERMINAL_STATUSES } }, + ], + }, ], } diff --git a/ondeck/src/app/api/clients/[id]/tasks/route.ts b/ondeck/src/app/api/clients/[id]/tasks/route.ts index 94dddd4..338c3c9 100644 --- a/ondeck/src/app/api/clients/[id]/tasks/route.ts +++ b/ondeck/src/app/api/clients/[id]/tasks/route.ts @@ -26,18 +26,21 @@ export async function GET( const where: any = { clientId: id } if (!showArchived) { - where.policy = { - OR: [ - { is: null }, - { status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } }, - ], + // Exclude tasks on dead policies + where.NOT = { + policy: { status: { in: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] } }, } - where.NOT = [ - { policyGroup: { renewalDate: { lt: cutoff } } }, + // Exclude tasks on expired renewal groups + where.OR = [ + { policyGroupId: null }, + { policyGroup: { renewalDate: { gte: cutoff } } }, + ] + // Only show recent or terminal tasks + where.AND = [ { - AND: [ - { dueDate: { lt: cutoff } }, - { status: { notIn: ['COMPLETED', 'CANCELLED', 'NA'] } }, + OR: [ + { dueDate: { gte: cutoff } }, + { status: { in: ['COMPLETED', 'CANCELLED', 'NA'] } }, ], }, ]