Files
FPT/src/app/api/plans/[planId]/analyses/[analysisId]/route.ts
T
admGitAICDS fb70781e5b
Deploy App / deploy (push) Successful in 1m45s
Navigation auf Plan-Ebene und gespeicherte Analysen (Roadmap-Redesign)
Sidebar zweistufig: pro Plan die Unterpunkte Szenarien / Effektive Werte /
Analysen; Klick auf Plan-Name oeffnet ein Plan-Dashboard.

Plan-Dashboard: Kennzahlen, gerechnete Werte ausdruecklich "laut
Basisszenario", Ist-Abweichung falls erfasst.

Szenario-Liste: Version, Elementzahl, Endvermoegen, Ruinalter + Aktionen
Historie und Matrix. Baum in der Sidebar bleibt.

Analysen: vier umklappende Kacheln (auch per Antippen). Grafiken oeffnen
neu mit Auswahl EINER Grafik. Szenario-Vergleich zu den Grafiken,
CSV-Export auf die Matrix.

Gespeicherte Analysen: Grafik/MC/Einflussfaktoren als ZAHLEN einfrieren
(read-only, nichts wird neu gerechnet) -- druckfaehig fuer den spaeteren
PDF-Bericht, ohne finalWealthSorted. Einheitliche generische Ergebnisform.

Neue Tabelle SavedAnalysis, Endpunkte /analyses und /dashboard, Module
analyses.ts, Komponenten PlanViews/SavedAnalysisView/SaveAnalysisButton.
Kein Eingriff in den Rechenkern. Spezifikation 0.24 (3.10 und 9.30 neu).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 22:21:02 +02:00

53 lines
1.7 KiB
TypeScript

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 });
}