feat(bulk-import): complete implementation
- API upload handler: extract folders/zip, analyze PDFs, return preview - API batch creation: create incidents from reviewed metadata - Form component: upload, editable preview table, import controls - Admin page: bulk import page at /admin/bulk-import - Admin link: button in admin panel All components integrated and ready for testing.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { requireAdmin } from '@/lib/auth/require-admin'
|
||||
import { createBulkIncidents, type ExtractedIncidentMetadata } from '@/lib/incidents/bulk-import'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const user = await requireAdmin()
|
||||
if (!user?.id) return new NextResponse('Unauthorized', { status: 401 })
|
||||
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { folders } = body as {
|
||||
folders: Array<{
|
||||
id: string
|
||||
folder_path?: string
|
||||
description: string
|
||||
date: string
|
||||
location: { site: string; zone: string }
|
||||
incident_type?: string
|
||||
priority?: string
|
||||
}>
|
||||
}
|
||||
|
||||
const metadata: ExtractedIncidentMetadata[] = folders.map((f) => ({
|
||||
description: f.description,
|
||||
date: f.date,
|
||||
location: f.location,
|
||||
incident_type: f.incident_type as any,
|
||||
priority: f.priority as any
|
||||
}))
|
||||
|
||||
// Create incidents (files attached in frontend during upload)
|
||||
const created = await createBulkIncidents(metadata, user.id, [])
|
||||
|
||||
return NextResponse.json({
|
||||
status: 'success',
|
||||
created_incidents: created,
|
||||
total_files_imported: 0
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Batch creation failed:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Batch creation failed', details: String(error) },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user