fix(dashboard): compute CAPA overdue count from due_date instead of status field

This commit is contained in:
2026-07-28 16:31:45 +08:00
parent 1103d842d5
commit 87251b3fc6
+6 -2
View File
@@ -4,7 +4,7 @@ import { asAdmin } from '@/lib/db/with-user'
import { redirect } from 'next/navigation' import { redirect } from 'next/navigation'
import { getSession } from '@/lib/auth/get-session' import { getSession } from '@/lib/auth/get-session'
import { incidents, sites, capaActions } from '@/lib/db/schema' 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 { StatCard } from '@/components/dashboard/stat-card'
import { RiskFlagsPanel } from '@/components/dashboard/risk-flags-panel' import { RiskFlagsPanel } from '@/components/dashboard/risk-flags-panel'
@@ -14,6 +14,7 @@ export default async function ManagementPage() {
if (!['management', 'admin'].includes(session.role)) redirect('/') if (!['management', 'admin'].includes(session.role)) redirect('/')
const now = new Date() const now = new Date()
const today = now.toISOString().slice(0, 10)
const thisMonthStart = new Date(now.getFullYear(), now.getMonth(), 1).toISOString() const thisMonthStart = new Date(now.getFullYear(), now.getMonth(), 1).toISOString()
const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 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() const thirtyDaysAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000).toISOString()
@@ -49,7 +50,10 @@ export default async function ManagementPage() {
asAdmin(db => asAdmin(db =>
db.select({ id: capaActions.id }) db.select({ id: capaActions.id })
.from(capaActions) .from(capaActions)
.where(eq(capaActions.status, 'overdue')) .where(and(
inArray(capaActions.status, ['open', 'in_progress']),
lt(capaActions.dueDate, today)
))
), ),
]) ])