32adfb4476
Deploy App / deploy (push) Successful in 1m51s
- Theming: semantische CSS-Tokens + 3 waehlbare Schemata (Hell/Dunkel/Warm/Sunset), Umschalter im Profil-Menue, FOUC-frei via Inline-Script, localStorage; Klassen-Sweep aller Komponenten, Recharts aus Tokens - Datenmodell: Household entfaellt; Plan traegt Haushaltsform/Personen/Inflation selbst (Person -> planId, Plan -> userId); destruktive Migration (TRUNCATE); Onboarding/HouseholdSettings entfernt; Plan-Erstellung & -Einstellungen mit Profilfeldern - Popups: Element-Erstellung mit Inline-Feldern (geteilte ElementPhaseFields/ElementTransitionFields), Phase- und Plan-Popups mit Direkteingabe - Zahlenfelder: 1'000er-Runden entfernt (floorToThousand/roundToHundred weg), integer MoneyInput mit beschleunigendem Press-and-Hold-Spinner, 0-Bug-Fix, harte Live-Caps - Quote: Amortisation + Tilgung neu quotenwirksam; Restquote sichtbar (sinkt beim Verteilen); Invest-Deckel = verfuegbares Kapital + fortgeschriebener Zielwert - Carry-Forward: Startwert der Folgephase = Zielwert der Vorphase minus Uebergangs-Bezug (live abgeleitet); optionale Zusatzinvestition aus verfuegbarem Kapital - Matrix: Zelle zeigt Start -> Ziel; Uebergangs-Spaltenkopf mit "n offen"-Badge + gefuehrtem Pruef-Panel Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
3.2 KiB
TypeScript
87 lines
3.2 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { prisma } from "@/lib/db";
|
|
import { toPlanInput, getOwnedPlan } from "@/lib/queries";
|
|
import { getCurrentUserId } from "@/lib/session";
|
|
import { computePlan } from "@/lib/calculations";
|
|
import { planProfileSchema, validatePersonsForType } from "@/app/api/plans/route";
|
|
|
|
export async function GET(
|
|
_request: NextRequest,
|
|
{ params }: { params: Promise<{ planId: string }> }
|
|
) {
|
|
const userId = await getCurrentUserId();
|
|
if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
|
const { planId } = await params;
|
|
|
|
const plan = await getOwnedPlan(planId, userId);
|
|
if (!plan) return NextResponse.json({ error: "Plan nicht gefunden." }, { status: 404 });
|
|
|
|
const planInput = toPlanInput(plan);
|
|
const computed = computePlan(planInput);
|
|
|
|
return NextResponse.json({ plan: planInput, computed });
|
|
}
|
|
|
|
// Name allein aendern ODER das ganze Plan-Profil (Haushaltsform/Personen/Inflation).
|
|
const patchSchema = z.union([
|
|
z.object({ name: z.string().min(1).max(120) }),
|
|
planProfileSchema.extend({ name: z.string().min(1).max(120).optional() }),
|
|
]);
|
|
|
|
export async function PATCH(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ planId: string }> }
|
|
) {
|
|
const userId = await getCurrentUserId();
|
|
if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
|
const { planId } = await params;
|
|
|
|
const plan = await prisma.plan.findFirst({ where: { id: planId, userId } });
|
|
if (!plan) return NextResponse.json({ error: "Plan nicht gefunden." }, { status: 404 });
|
|
|
|
const body = await request.json();
|
|
const parsed = patchSchema.safeParse(body);
|
|
if (!parsed.success) return NextResponse.json({ error: "Ungueltige Eingabe." }, { status: 400 });
|
|
|
|
const data = parsed.data;
|
|
const hasProfile = "householdType" in data;
|
|
|
|
if (hasProfile) {
|
|
const error = validatePersonsForType(data);
|
|
if (error) return NextResponse.json({ error }, { status: 400 });
|
|
const updated = await prisma.$transaction(async (tx) => {
|
|
await tx.person.deleteMany({ where: { planId: plan.id } });
|
|
return tx.plan.update({
|
|
where: { id: plan.id },
|
|
data: {
|
|
name: data.name ?? undefined,
|
|
householdType: data.householdType,
|
|
inflationRateDefault: data.inflationRateDefault,
|
|
persons: { create: data.persons },
|
|
},
|
|
});
|
|
});
|
|
return NextResponse.json({ plan: { id: updated.id, name: updated.name } });
|
|
}
|
|
|
|
const updated = await prisma.plan.update({
|
|
where: { id: plan.id },
|
|
data: { name: data.name },
|
|
});
|
|
return NextResponse.json({ plan: { id: updated.id, name: updated.name } });
|
|
}
|
|
|
|
export async function DELETE(
|
|
_request: NextRequest,
|
|
{ params }: { params: Promise<{ planId: string }> }
|
|
) {
|
|
const userId = await getCurrentUserId();
|
|
if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
|
const { planId } = await params;
|
|
const plan = await prisma.plan.findFirst({ where: { id: planId, userId } });
|
|
if (!plan) return NextResponse.json({ error: "Plan nicht gefunden." }, { status: 404 });
|
|
await prisma.plan.delete({ where: { id: plan.id } });
|
|
return NextResponse.json({ ok: true });
|
|
}
|