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]/route.ts
1.4 KB
import { NextResponse } from "next/server";
import {
  getMissionView,
  updateMission,
  MissionError,
} from "@/lib/missions/manager";
import type { UpdateMissionInput } from "@/lib/missions/types";

/**
 * A single mission.
 *
 *   GET   /api/missions/:id  → mission + history + reports (collects new reports)
 *   PATCH /api/missions/:id  → edit mission fields
 */

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

export async function GET(
  _request: Request,
  { params }: { params: { id: string } },
) {
  const view = getMissionView(params.id);
  if (!view) {
    return NextResponse.json({ error: "Mission not found." }, { status: 404 });
  }
  return NextResponse.json(view);
}

export async function PATCH(
  request: Request,
  { params }: { params: { id: string } },
) {
  let body: UpdateMissionInput;
  try {
    body = (await request.json()) as UpdateMissionInput;
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  try {
    const mission = updateMission(params.id, body);
    return NextResponse.json({ mission });
  } catch (err) {
    if (err instanceof MissionError) {
      return NextResponse.json({ error: err.message }, { status: err.status });
    }
    const message = err instanceof Error ? err.message : "Update failed.";
    return NextResponse.json({ error: message }, { status: 500 });
  }
}

root · /srv/aaf