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]/risks/route.ts
1.0 KB
import { NextResponse } from "next/server";
import {
createRisk,
listRisksWithHistory,
GovernanceError,
} from "@/lib/missions/governance";
import type { CreateRiskInput } from "@/lib/missions/governance";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(
_r: Request,
{ params }: { params: { id: string } },
) {
return NextResponse.json({ risks: listRisksWithHistory(params.id) });
}
export async function POST(request: Request, { params }: { params: { id: string } }) {
let body: CreateRiskInput;
try {
body = (await request.json()) as CreateRiskInput;
} catch {
return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
}
try {
return NextResponse.json({ risk: createRisk(params.id, body) }, { status: 201 });
} catch (err) {
if (err instanceof GovernanceError)
return NextResponse.json({ error: err.message }, { status: err.status });
return NextResponse.json({ error: "Could not create risk." }, { status: 500 });
}
}
root · /srv/aaf