import { NextRequest, NextResponse } from "next/server"; import { toErrorResponse } from "@/lib/render-pipeline/errors"; import { requirePipelineAdmin } from "@/lib/render-pipeline/session-auth"; import { overrideValidation, overrideValidationSchema } from "@/lib/render-pipeline/validation"; // ── POST /api/render/exports/{exportId}/override-validation ────────────────── // // A human overruling a failed validation run. Resumes the pipeline at the // preview stage, so the export still goes through QC; the failed checks stay on // record and keep showing up as warnings in the QC queue. export async function POST( req: NextRequest, { params }: { params: Promise<{ exportId: string }> } ) { try { // Waving a failed check through is a supervisor's call, not any user's. const user = await requirePipelineAdmin(); const { exportId } = await params; let raw: unknown; try { raw = await req.json(); } catch { return NextResponse.json({ error: "Invalid JSON" }, { status: 400 }); } const parsed = overrideValidationSchema.safeParse(raw); if (!parsed.success) { return NextResponse.json({ error: "A reason is required", details: parsed.error.issues }, { status: 422 }); } const result = await overrideValidation(exportId, { reason: parsed.data.reason, skipPreview: parsed.data.skipPreview, userId: user.id, userName: user.name ?? user.email ?? null, }); return NextResponse.json(result); } catch (err) { const { body, status } = toErrorResponse(err); return NextResponse.json(body, { status }); } }