Files
Converge/src/app/api/assessments/[id]/surveys/route.ts
Chris Olson d5c77543e8 Initial commit: Converge portfolio rationalization app
Next.js app for mapping a customer's competitive tool landscape onto our
portfolio and building the consolidation business case: assessment
workbench, customer report and Word export, product catalog, competitive
knowledge base, dossier import, shareable landscape questionnaires with a
review inbox, tool-footprint and business-unit value analysis, and an
implementation timeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 11:48:42 -04:00

26 lines
1.3 KiB
TypeScript

import { NextResponse } from "next/server";
import { createSurvey, getAssessment, getCatalog, listSurveys } from "@/lib/store";
import { surveyableDomains } from "@/lib/survey";
type Ctx = { params: Promise<{ id: string }> };
export async function GET(_req: Request, { params }: Ctx) {
const { id } = await params;
if (!(await getAssessment(id))) return NextResponse.json({ error: "Not found" }, { status: 404 });
return NextResponse.json(await listSurveys(id));
}
export async function POST(req: Request, { params }: Ctx) {
const { id } = await params;
if (!(await getAssessment(id))) return NextResponse.json({ error: "Not found" }, { status: 404 });
const body = (await req.json()) as { respondentName?: string; domains?: string[] };
// Keep catalog order and drop anything that is not a live category.
const wanted = new Set(Array.isArray(body.domains) ? body.domains : []);
const domains = surveyableDomains(await getCatalog()).map((d) => d.id).filter((d) => wanted.has(d));
if (!domains.length) return NextResponse.json({ error: "Pick at least one category." }, { status: 400 });
const name = typeof body.respondentName === "string" ? body.respondentName.trim().slice(0, 120) : "";
return NextResponse.json(await createSurvey(id, name, domains));
}