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)
This commit is contained in:
parent
02afceb0c5
commit
4e54b7e38c
2 changed files with 5 additions and 7 deletions
|
|
@ -97,10 +97,9 @@ export async function POST(request: NextRequest) {
|
||||||
|
|
||||||
log.push(`Group tasks created: ${groupTasksCreated}`)
|
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({
|
const ungroupedPolicies = await prisma.policy.findMany({
|
||||||
where: {
|
where: {
|
||||||
policyGroupId: null,
|
|
||||||
expirationDate: { gte: new Date() },
|
expirationDate: { gte: new Date() },
|
||||||
status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] as any[] },
|
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({
|
const templates = await prisma.taskTemplate.findMany({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
level: { in: ['BOTH', 'POLICY'] as any[] },
|
level: 'POLICY' as any,
|
||||||
OR: [
|
OR: [
|
||||||
{ designationId: null },
|
{ designationId: null },
|
||||||
...(designationIds.length > 0 ? [{ designationId: { in: designationIds } }] : []),
|
...(designationIds.length > 0 ? [{ designationId: { in: designationIds } }] : []),
|
||||||
|
|
@ -195,7 +194,7 @@ export async function POST(request: NextRequest) {
|
||||||
designation2Id: true,
|
designation2Id: true,
|
||||||
claimsAdvocateId: true,
|
claimsAdvocateId: true,
|
||||||
policyGroups: { select: { renewalDate: 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
|
if (!clientRecord) continue
|
||||||
|
|
|
||||||
|
|
@ -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({
|
const ungroupedPolicies = await prisma.policy.findMany({
|
||||||
where: {
|
where: {
|
||||||
policyGroupId: null,
|
|
||||||
expirationDate: { gte: new Date() },
|
expirationDate: { gte: new Date() },
|
||||||
status: { notIn: ['Cancelled', 'Expired', 'Non-Renewed', 'Rewritten', 'Not taken'] },
|
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({
|
const templates = await prisma.taskTemplate.findMany({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
level: { in: ['BOTH', 'POLICY'] },
|
level: 'POLICY',
|
||||||
OR: [
|
OR: [
|
||||||
{ designationId: null },
|
{ designationId: null },
|
||||||
...(designationIds.length > 0 ? [{ designationId: { in: designationIds } }] : []),
|
...(designationIds.length > 0 ? [{ designationId: { in: designationIds } }] : []),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue