diff --git a/app/(protected)/management/page.tsx b/app/(protected)/management/page.tsx index e47015a..35feece 100644 --- a/app/(protected)/management/page.tsx +++ b/app/(protected)/management/page.tsx @@ -4,7 +4,7 @@ import { asAdmin } from '@/lib/db/with-user' import { redirect } from 'next/navigation' import { getSession } from '@/lib/auth/get-session' import { incidents, sites, capaActions } from '@/lib/db/schema' -import { eq, gte, lt, and } from 'drizzle-orm' +import { eq, gte, lt, and, inArray } from 'drizzle-orm' import { StatCard } from '@/components/dashboard/stat-card' import { RiskFlagsPanel } from '@/components/dashboard/risk-flags-panel' @@ -14,6 +14,7 @@ export default async function ManagementPage() { if (!['management', 'admin'].includes(session.role)) redirect('/') const now = new Date() + const today = now.toISOString().slice(0, 10) const thisMonthStart = new Date(now.getFullYear(), now.getMonth(), 1).toISOString() const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1).toISOString() const thirtyDaysAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000).toISOString() @@ -49,7 +50,10 @@ export default async function ManagementPage() { asAdmin(db => db.select({ id: capaActions.id }) .from(capaActions) - .where(eq(capaActions.status, 'overdue')) + .where(and( + inArray(capaActions.status, ['open', 'in_progress']), + lt(capaActions.dueDate, today) + )) ), ])