fix: replace any casts with typed casts for Supabase join results
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWxyMibCuGGtSQSqfajDQ7
This commit is contained in:
@@ -26,7 +26,7 @@ export async function GET() {
|
|||||||
|
|
||||||
const siteMap: Record<string, number> = {}
|
const siteMap: Record<string, number> = {}
|
||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
const name = (r.sites as any)?.name ?? 'Unknown'
|
const name = (r.sites as { name: string } | null)?.name ?? 'Unknown'
|
||||||
siteMap[name] = (siteMap[name] ?? 0) + 1
|
siteMap[name] = (siteMap[name] ?? 0) + 1
|
||||||
}
|
}
|
||||||
const by_site = Object.entries(siteMap).map(([name, count]) => ({ name, count }))
|
const by_site = Object.entries(siteMap).map(([name, count]) => ({ name, count }))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { createClient } from '@/lib/supabase/server'
|
import { createClient } from '@/lib/supabase/server'
|
||||||
import { validateIncidentInput } from '@/lib/incidents/validate'
|
import { validateIncidentInput, type IncidentType, type MedicalStatus } from '@/lib/incidents/validate'
|
||||||
import { uploadEvidenceFile, type EvidenceStage } from '@/lib/supabase/storage'
|
import { uploadEvidenceFile, type EvidenceStage } from '@/lib/supabase/storage'
|
||||||
import { sendNewIncidentEmail } from '@/lib/notifications/email'
|
import { sendNewIncidentEmail } from '@/lib/notifications/email'
|
||||||
|
|
||||||
@@ -28,11 +28,11 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const input = {
|
const input = {
|
||||||
zone_token: body.zone_token as string,
|
zone_token: body.zone_token as string,
|
||||||
incident_type: body.incident_type as any,
|
incident_type: body.incident_type as IncidentType,
|
||||||
description: body.description as string,
|
description: body.description as string,
|
||||||
injury_involved: body.injury_involved === 'true' || body.injury_involved === true,
|
injury_involved: body.injury_involved === 'true' || body.injury_involved === true,
|
||||||
asset_involved: body.asset_involved === 'true' || body.asset_involved === true,
|
asset_involved: body.asset_involved === 'true' || body.asset_involved === true,
|
||||||
medical_status: body.medical_status as any || undefined,
|
medical_status: body.medical_status as MedicalStatus | undefined || undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
const validation = validateIncidentInput(input)
|
const validation = validateIncidentInput(input)
|
||||||
|
|||||||
+2
-2
@@ -32,13 +32,13 @@ export default async function ReportPage({ searchParams }: Props) {
|
|||||||
<h1 className="text-2xl font-bold text-gray-900">Report an Incident</h1>
|
<h1 className="text-2xl font-bold text-gray-900">Report an Incident</h1>
|
||||||
{zoneData ? (
|
{zoneData ? (
|
||||||
<p className="text-sm text-gray-600 mt-1">
|
<p className="text-sm text-gray-600 mt-1">
|
||||||
{(zoneData.sites as any)?.name ?? 'Unknown Site'} — {zoneData.name}
|
{zoneData.sites.name} — {zoneData.name}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-sm text-amber-600 mt-1">No zone detected — zone will not be recorded</p>
|
<p className="text-sm text-amber-600 mt-1">No zone detected — zone will not be recorded</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<ReportForm zoneToken={zone ?? null} zoneName={zoneData?.name ?? null} siteName={(zoneData?.sites as any)?.name ?? null} />
|
<ReportForm zoneToken={zone ?? null} zoneName={zoneData?.name ?? null} siteName={zoneData?.sites.name ?? null} />
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ export async function sendNewIncidentEmail(
|
|||||||
.eq('id', incidentId)
|
.eq('id', incidentId)
|
||||||
.single()
|
.single()
|
||||||
|
|
||||||
const siteName = (incident?.sites as any)?.name ?? 'Unknown Site'
|
const siteName = (incident?.sites as { name: string } | null)?.name ?? 'Unknown Site'
|
||||||
const reporterName = (incident?.reporter as any)?.name ?? 'Unknown'
|
const reporterName = (incident?.reporter as { name: string } | null)?.name ?? 'Unknown'
|
||||||
const reportedAt = incident?.reported_at
|
const reportedAt = incident?.reported_at
|
||||||
? new Date(incident.reported_at).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })
|
? new Date(incident.reported_at).toLocaleString('en-MY', { timeZone: 'Asia/Kuala_Lumpur' })
|
||||||
: '-'
|
: '-'
|
||||||
|
|||||||
Reference in New Issue
Block a user