feat: incident report form, API route, middleware shared-route + redirect
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
export const INCIDENT_TYPES = ['injury', 'near_miss', 'hazard', 'asset_damage', 'environmental', 'security', 'fire'] as const
|
||||
export const MEDICAL_STATUSES = ['none', 'first_aid', 'medical_treatment', 'lti'] as const
|
||||
|
||||
export type IncidentType = typeof INCIDENT_TYPES[number]
|
||||
export type MedicalStatus = typeof MEDICAL_STATUSES[number]
|
||||
|
||||
export interface IncidentInput {
|
||||
zone_token: string
|
||||
incident_type: IncidentType
|
||||
description: string
|
||||
injury_involved: boolean
|
||||
medical_status?: MedicalStatus
|
||||
asset_involved: boolean
|
||||
}
|
||||
|
||||
export function validateIncidentInput(input: IncidentInput): { ok: boolean; errors: string[] } {
|
||||
const errors: string[] = []
|
||||
|
||||
if (!input.zone_token?.trim()) errors.push('zone_token is required')
|
||||
if (input.description.trim().length < 10) errors.push('description must be at least 10 characters')
|
||||
if (!INCIDENT_TYPES.includes(input.incident_type)) errors.push('incident_type is invalid')
|
||||
if (input.injury_involved && !input.medical_status) errors.push('medical_status is required when injury is involved')
|
||||
if (input.medical_status && !MEDICAL_STATUSES.includes(input.medical_status)) errors.push('medical_status is invalid')
|
||||
|
||||
return { ok: errors.length === 0, errors }
|
||||
}
|
||||
Reference in New Issue
Block a user