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]/objectives/route.ts
1.4 KB
import { NextResponse } from "next/server";
import {
  createObjective,
  listObjectives,
  missionProgress,
  ObjectiveError,
} from "@/lib/missions/objectives";
import type { CreateObjectiveInput } from "@/lib/missions/types";

/**
 * Objectives of a mission (PASS M2).
 *
 *   GET  /api/missions/:id/objectives  → objectives + mission progress
 *   POST /api/missions/:id/objectives  → create an objective (status: Draft)
 */

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

export async function GET(
  _request: Request,
  { params }: { params: { id: string } },
) {
  return NextResponse.json({
    objectives: listObjectives(params.id),
    progress: missionProgress(params.id),
  });
}

export async function POST(
  request: Request,
  { params }: { params: { id: string } },
) {
  let body: CreateObjectiveInput;
  try {
    body = (await request.json()) as CreateObjectiveInput;
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  try {
    const objective = createObjective(params.id, body);
    return NextResponse.json({ objective }, { status: 201 });
  } catch (err) {
    if (err instanceof ObjectiveError) {
      return NextResponse.json({ error: err.message }, { status: err.status });
    }
    const message = err instanceof Error ? err.message : "Could not create objective.";
    return NextResponse.json({ error: message }, { status: 500 });
  }
}

root · /srv/aaf