import { NextResponse } from "next/server"; import { createRequest, listRequests, validateCreateRequestInput } from "@/lib/requests"; export async function POST(request: Request): Promise { let body: unknown; try { body = await request.json(); } catch { return NextResponse.json({ error: "Request body must be valid JSON" }, { status: 400 }); } if (typeof body !== "object" || body === null) { return NextResponse.json({ error: "Request body must be a JSON object" }, { status: 400 }); } const { employee_id, type, reason } = body as Record; const validation = validateCreateRequestInput({ employee_id, type, reason }); if (!validation.ok) { return NextResponse.json({ error: validation.error }, { status: 400 }); } const created = await createRequest(validation.value); return NextResponse.json(created, { status: 201 }); } export async function GET(): Promise { const requests = await listRequests(); return NextResponse.json(requests, { status: 200 }); }