Intelligence

Artifacts

Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.

Repository
globals.csslayout.tsxnot-found.tsxpage.tsx
.gitignoreDockerfilenext-env.d.tsnext.config.mjspackage-lock.jsonpackage.jsonpostcss.config.mjsREADME.mdtailwind.config.tstsconfig.jsontsconfig.tsbuildinfo
README.md
CONSTITUTION_COMPLIANCE_AUDIT_V1.mdREADME.md
repositories/aaf-holdings/hq01/app/api/missions/[id]/kpis/route.ts
1.0 KB
import { NextResponse } from "next/server";
import {
  createKpi,
  listKpisWithHistory,
  GovernanceError,
} from "@/lib/missions/governance";
import type { CreateKpiInput } 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({ kpis: listKpisWithHistory(params.id) });
}

export async function POST(request: Request, { params }: { params: { id: string } }) {
  let body: CreateKpiInput;
  try {
    body = (await request.json()) as CreateKpiInput;
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  try {
    return NextResponse.json({ kpi: createKpi(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 KPI." }, { status: 500 });
  }
}

root · /srv/aaf