Intelligence
Artifacts
Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.
Repository
repositories/aaf-holdings/hq01/app/api/missions/[id]/transition/route.ts
1.2 KB
import { NextResponse } from "next/server";
import { transitionMission, MissionError } from "@/lib/missions/manager";
import type { MissionStatus } from "@/lib/missions/types";
/**
* Transition a mission to a new lifecycle state (PASS M1).
*
* POST /api/missions/:id/transition { to, reason? }
*
* Invalid transitions are rejected by the state machine.
*/
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(
request: Request,
{ params }: { params: { id: string } },
) {
let body: { to?: MissionStatus; reason?: string };
try {
body = await request.json();
} catch {
return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
}
if (!body.to) {
return NextResponse.json({ error: "Target state 'to' is required." }, { status: 400 });
}
try {
const mission = transitionMission(params.id, body.to, { reason: body.reason });
return NextResponse.json({ ok: true, mission });
} catch (err) {
if (err instanceof MissionError) {
return NextResponse.json({ error: err.message }, { status: err.status });
}
const message = err instanceof Error ? err.message : "Transition failed.";
return NextResponse.json({ error: message }, { status: 500 });
}
}
root · /srv/aaf