From 4e54b7e38c03fafa06ef6ecd41e3f08e8f484068 Mon Sep 17 00:00:00 2001 From: lorentz Date: Mon, 13 Apr 2026 20:25:10 +0000 Subject: [PATCH] Fix: POLICY-level tasks now generated for all active policies (grouped or not) - Historical reset: removed policyGroupId: null filter from policy loop, use level POLICY only - Gap fill: same fix - all active future policies get POLICY-level tasks - BOTH-level templates remain on groups (for grouped) or policies (for ungrouped) - ~3500 grouped policies were missing their POLICY tasks (loss runs, mod factor, etc) --- ondeck/src/app/api/admin/gap-fill/route.ts | 7 +++---- ondeck/src/app/api/admin/historical-reset/route.ts | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ondeck/src/app/api/admin/gap-fill/route.ts b/ondeck/src/app/api/admin/gap-fill/route.ts index a4352c2..45a7c91 100644 --- a/ondeck/src/app/api/admin/gap-fill/route.ts +++ b/ondeck/src/app/api/admin/gap-fill/route.ts @@ -97,10 +97,9 @@ export async function POST(request: NextRequest) { log.push(`Group tasks created: ${groupTasksCreated}`) - // ── 2. Policy-level tasks (ungrouped policies only) ───────────────────── + // ── 2. Policy-level tasks (all active policies — grouped or not) ──────── const ungroupedPolicies = await prisma.policy.findMany({ where: { - policyGroupId: null, expirationDate: { gte: new Date() }, status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] as any[] }, }, @@ -119,7 +118,7 @@ export async function POST(request: NextRequest) { const templates = await prisma.taskTemplate.findMany({ where: { isActive: true, - level: { in: ['BOTH', 'POLICY'] as any[] }, + level: 'POLICY' as any, OR: [ { designationId: null }, ...(designationIds.length > 0 ? [{ designationId: { in: designationIds } }] : []), @@ -195,7 +194,7 @@ export async function POST(request: NextRequest) { designation2Id: true, claimsAdvocateId: true, policyGroups: { select: { renewalDate: true } }, - policies: { where: { policyGroupId: null }, select: { expirationDate: true } }, + policies: { where: { expirationDate: { gte: new Date() }, status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] as any[] } }, select: { expirationDate: true } }, }, }) if (!clientRecord) continue diff --git a/ondeck/src/app/api/admin/historical-reset/route.ts b/ondeck/src/app/api/admin/historical-reset/route.ts index dd81f80..ee9192a 100644 --- a/ondeck/src/app/api/admin/historical-reset/route.ts +++ b/ondeck/src/app/api/admin/historical-reset/route.ts @@ -209,10 +209,9 @@ export async function POST(request: NextRequest) { } } - // Policy-level tasks (ungrouped policies) + // Policy-level tasks (all active policies — grouped or not) const ungroupedPolicies = await prisma.policy.findMany({ where: { - policyGroupId: null, expirationDate: { gte: new Date() }, status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] }, }, @@ -240,7 +239,7 @@ export async function POST(request: NextRequest) { const templates = await prisma.taskTemplate.findMany({ where: { isActive: true, - level: { in: ['BOTH', 'POLICY'] }, + level: 'POLICY', OR: [ { designationId: null }, ...(designationIds.length > 0 ? [{ designationId: { in: designationIds } }] : []),