import { NextRequest, NextResponse } from "next/server"; import { prisma } from "@/lib/db"; import { getCurrentUserId } from "@/lib/session"; // Eine einzelne gespeicherte Analyse MIT den Zahlen (Eingaben + Ergebnis) -- zum Öffnen der // read-only Ansicht. export async function GET( _request: NextRequest, { params }: { params: Promise<{ planId: string; analysisId: string }> } ) { const userId = await getCurrentUserId(); if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 }); const { planId, analysisId } = await params; const a = await prisma.savedAnalysis.findFirst({ where: { id: analysisId, planId, plan: { userId } }, }); if (!a) return NextResponse.json({ error: "Analyse nicht gefunden." }, { status: 404 }); return NextResponse.json({ analysis: { id: a.id, name: a.name, type: a.type, scenarioName: a.scenarioName, versionLabel: a.versionLabel, metric: a.metric, source: a.source, summary: a.summary, inputs: a.inputs, result: a.result, createdAt: a.createdAt, }, }); } export async function DELETE( _request: NextRequest, { params }: { params: Promise<{ planId: string; analysisId: string }> } ) { const userId = await getCurrentUserId(); if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 }); const { planId, analysisId } = await params; const a = await prisma.savedAnalysis.findFirst({ where: { id: analysisId, planId, plan: { userId } }, }); if (!a) return NextResponse.json({ error: "Analyse nicht gefunden." }, { status: 404 }); await prisma.savedAnalysis.delete({ where: { id: analysisId } }); return NextResponse.json({ ok: true }); }