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]/assignments/route.ts
1.4 KB
import { NextResponse } from "next/server";
import {
  createAssignment,
  listAssignments,
  AssignmentError,
} from "@/lib/missions/assignments";
import type { CreateAssignmentInput } from "@/lib/missions/types";

/**
 * Assignments of a mission (PASS M3). Creating an assignment auto-generates its
 * immutable execution context.
 *
 *   GET  /api/missions/:id/assignments  → list
 *   POST /api/missions/:id/assignments  → create (for a work order)
 */

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

export async function GET(
  _request: Request,
  { params }: { params: { id: string } },
) {
  return NextResponse.json({ assignments: listAssignments(params.id) });
}

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

root · /srv/aaf