import { NextRequest, NextResponse } from "next/server"; import { isExtAuthorized } from "@/lib/render-pipeline/ext-auth"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { qcSubmitSchema, submitQCReview } from "@/lib/render-pipeline/qc"; // ── POST /api/ext/exports/{exportId}/qc (E4) ───────────────────────────────── // // QC Pass / QC Fail from the AE panel. PASS → READY_FOR_DELIVERY and nothing // else; FAIL → QC_FAILED and the comp task back to CHANGES (§10.2). export async function POST( req: NextRequest, { params }: { params: Promise<{ exportId: string }> } ) { if (!isExtAuthorized(req)) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { exportId } = await params; let raw: unknown; try { raw = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } const parsed = qcSubmitSchema.safeParse(raw); if (!parsed.success) { return NextResponse.json({ error: "Invalid QC submission", details: parsed.error.issues }, { status: 422 }); } try { const result = await submitQCReview(exportId, parsed.data, { source: "AE_PANEL" }); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }