fix(db): phase 4 group 6 — session guard, type safety, SQL filter fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,7 @@ export default async function CapaListPage() {
|
||||
← Incidents
|
||||
</Link>
|
||||
</div>
|
||||
<CapaBoard capas={capas as Parameters<typeof CapaBoard>[0]['capas']} />
|
||||
<CapaBoard capas={capas} />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { asAdmin } from '@/lib/db/with-user'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { getSession } from '@/lib/auth/get-session'
|
||||
import { incidents, sites, zones, capaActions, doshReports, investigations } from '@/lib/db/schema'
|
||||
import { eq, gte, isNotNull } from 'drizzle-orm'
|
||||
import { eq, gte, isNotNull, and } from 'drizzle-orm'
|
||||
import { StatCard } from '@/components/dashboard/stat-card'
|
||||
import { bucketIncidentsByMonth, topRootCauses } from '@/lib/dashboard/trends'
|
||||
import { RiskFlagsPanel } from '@/components/dashboard/risk-flags-panel'
|
||||
@@ -67,8 +67,8 @@ export default async function HseDashboardPage({
|
||||
db.select({ zoneName: zones.name })
|
||||
.from(incidents)
|
||||
.leftJoin(zones, eq(incidents.zoneId, zones.id))
|
||||
.where(gte(incidents.reportedAt, ninetyDaysAgo))
|
||||
).then(rows => rows.filter(r => r.zoneName !== null)),
|
||||
.where(and(gte(incidents.reportedAt, ninetyDaysAgo), isNotNull(incidents.zoneId)))
|
||||
),
|
||||
asAdmin(db =>
|
||||
db.select({
|
||||
dueDate: capaActions.dueDate,
|
||||
@@ -133,6 +133,7 @@ export default async function HseDashboardPage({
|
||||
|
||||
const capas = completedCapas
|
||||
const onTime = capas.filter(c => {
|
||||
if (!c.dueDate) return false
|
||||
const due = new Date(c.dueDate)
|
||||
const done = c.verifiedAt
|
||||
? new Date(c.verifiedAt)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
import { notFound } from 'next/navigation'
|
||||
import { notFound, redirect } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { getSession } from '@/lib/auth/get-session'
|
||||
import { asAdmin } from '@/lib/db/with-user'
|
||||
import { incidents, sites, zones, trucks, users, evidenceFiles, investigations } from '@/lib/db/schema'
|
||||
import { eq, and } from 'drizzle-orm'
|
||||
@@ -16,6 +17,9 @@ interface Props {
|
||||
export default async function SupervisorIncidentDetailPage({ params }: Props) {
|
||||
const { id } = await params
|
||||
|
||||
const session = await getSession()
|
||||
if (!session) redirect('/login')
|
||||
|
||||
const reporterAlias = aliasedTable(users, 'reporter')
|
||||
const investigatorAlias = aliasedTable(users, 'investigator')
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { asAdmin } from '@/lib/db/with-user'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { getSession } from '@/lib/auth/get-session'
|
||||
import { incidents, sites, capaActions, users } from '@/lib/db/schema'
|
||||
import { eq, not, and, inArray, sql } from 'drizzle-orm'
|
||||
import { eq, not, and, inArray, sql, desc } from 'drizzle-orm'
|
||||
import { aliasedTable } from 'drizzle-orm'
|
||||
import { StatCard } from '@/components/dashboard/stat-card'
|
||||
|
||||
@@ -65,7 +65,7 @@ export default async function SupervisorPage() {
|
||||
})
|
||||
.from(incidents)
|
||||
.where(and(eq(incidents.siteId, session.siteId!), not(eq(incidents.status, 'closed'))))
|
||||
.orderBy(sql`${incidents.reportedAt} desc`)
|
||||
.orderBy(desc(incidents.reportedAt))
|
||||
.limit(10)
|
||||
),
|
||||
asAdmin(db =>
|
||||
|
||||
Reference in New Issue
Block a user