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/assets/[aid]/route.ts
1.4 KB
import { NextResponse } from "next/server";
import { getAssetView, updateAsset, AssetError } from "@/lib/assets/ledger";
import type { UpdateAssetInput } from "@/lib/assets/types";

/**
 * A single asset.
 *
 *   GET   /api/assets/:aid  → asset + history + full lineage
 *   PATCH /api/assets/:aid  → update metadata (tags/description/status/name/type)
 *
 * Origin lineage (mission/objective/work-order/assignment/report) can never change.
 */

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

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

export async function PATCH(
  request: Request,
  { params }: { params: { aid: string } },
) {
  let body: UpdateAssetInput;
  try {
    body = (await request.json()) as UpdateAssetInput;
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  try {
    const asset = updateAsset(params.aid, body);
    return NextResponse.json({ asset });
  } catch (err) {
    if (err instanceof AssetError) {
      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