@@ -2,7 +2,9 @@ import { NextRequest, NextResponse } from 'next/server';
22
33import { requireAdmin } from '@/server/lib/admin-auth' ;
44import { validateOptionalEventId } from '@/server/lib/admin-relations' ;
5- import { assertEnum , assertRequired , INSTALLATION_STATUSES , INSTALLATION_TYPES , MAP_ACTOR_KEYS , MAP_PRIORITIES , parseISODate , safeJson } from '@/server/lib/admin-validate' ;
5+ import { parseBodyWithSchema , toJsonValue } from '@/server/lib/admin-schema-utils' ;
6+ import { adminTargetCreateSchema } from '@/server/lib/admin-schemas' ;
7+ import { parseISODate } from '@/server/lib/admin-validate' ;
68import { err , ok } from '@/server/lib/api-utils' ;
79import { prisma } from '@/server/lib/db' ;
810import { checkMapFeatureEnforcement } from '@/server/lib/enforcement' ;
@@ -17,26 +19,9 @@ export async function POST(
1719 if ( denied ) return denied ;
1820
1921 const { conflictId } = await params ;
20- const body = await safeJson ( req ) ;
22+ const body = await parseBodyWithSchema ( req , adminTargetCreateSchema ) ;
2123 if ( body instanceof NextResponse ) return body ;
2224
23- const missing = assertRequired ( body , [ 'id' , 'actor' , 'priority' , 'category' , 'type' ] ) ;
24- if ( missing ) return err ( 'VALIDATION' , missing ) ;
25-
26- const actorErr = assertEnum ( body . actor , MAP_ACTOR_KEYS , 'actor' ) ;
27- if ( actorErr ) return err ( 'VALIDATION' , actorErr ) ;
28-
29- const priorityErr = assertEnum ( body . priority , MAP_PRIORITIES , 'priority' ) ;
30- if ( priorityErr ) return err ( 'VALIDATION' , priorityErr ) ;
31-
32- const typeErr = assertEnum ( body . type , INSTALLATION_TYPES , 'type' ) ;
33- if ( typeErr ) return err ( 'VALIDATION' , typeErr ) ;
34-
35- if ( body . status !== undefined && body . status !== null ) {
36- const statusErr = assertEnum ( body . status , INSTALLATION_STATUSES , 'status' ) ;
37- if ( statusErr ) return err ( 'VALIDATION' , statusErr ) ;
38- }
39-
4025 const geometry = normalizePointGeometry ( body . geometry ) ;
4126 if ( ! geometry ) {
4227 return err ( 'VALIDATION' , 'Target geometry requires position [lng, lat]' ) ;
@@ -79,7 +64,7 @@ export async function POST(
7964 status : body . status ?? null ,
8065 timestamp,
8166 geometry,
82- properties : body . properties ?? { } ,
67+ properties : toJsonValue ( body . properties ?? { } ) ,
8368 } ,
8469 } ) ;
8570
0 commit comments