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:
@@ -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