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.
This commit is contained in:
lorentz 2026-04-08 02:16:04 +00:00
parent 8aa20ea751
commit 8db7113c0b
3 changed files with 42 additions and 22 deletions

View file

@ -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'] } },
],
},
],
}
})(),

View file

@ -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 } },
],
},
],
}

View file

@ -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'] } },
],
},
]