V3: 3 Farbschemata, Grundprofil auf Plan-Ebene, Erstellungs-Popups, integer-Zahlenfelder mit Beschleunigungs-Spinner, Carry-Forward des Zielwerts, gefuehrter Uebergang
Deploy App / deploy (push) Successful in 1m51s
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>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { toHouseholdInput, toPlanInput, getHouseholdOrNull, getOwnedPlan } from "@/lib/queries";
|
||||
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,
|
||||
@@ -13,24 +14,20 @@ export async function GET(
|
||||
if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
||||
const { planId } = await params;
|
||||
|
||||
const household = await getHouseholdOrNull(userId);
|
||||
if (!household) return NextResponse.json({ error: "Kein Haushalt vorhanden." }, { status: 400 });
|
||||
|
||||
const plan = await getOwnedPlan(planId, userId);
|
||||
if (!plan) return NextResponse.json({ error: "Plan nicht gefunden." }, { status: 404 });
|
||||
|
||||
const householdInput = toHouseholdInput(household);
|
||||
const planInput = toPlanInput(plan);
|
||||
const computed = computePlan(planInput, householdInput);
|
||||
const computed = computePlan(planInput);
|
||||
|
||||
return NextResponse.json({ plan: planInput, computed });
|
||||
}
|
||||
|
||||
const patchSchema = z.object({
|
||||
name: z.string().min(1).max(120).optional(),
|
||||
retirementAgeA: z.number().int().min(30).max(100).nullable().optional(),
|
||||
retirementAgeB: z.number().int().min(30).max(100).nullable().optional(),
|
||||
});
|
||||
// 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,
|
||||
@@ -40,20 +37,37 @@ export async function PATCH(
|
||||
if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
||||
const { planId } = await params;
|
||||
|
||||
const plan = await prisma.plan.findFirst({ where: { id: planId, household: { userId } } });
|
||||
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: parsed.data.name ?? undefined,
|
||||
retirementAgeA: parsed.data.retirementAgeA === undefined ? undefined : parsed.data.retirementAgeA,
|
||||
retirementAgeB: parsed.data.retirementAgeB === undefined ? undefined : parsed.data.retirementAgeB,
|
||||
},
|
||||
data: { name: data.name },
|
||||
});
|
||||
return NextResponse.json({ plan: { id: updated.id, name: updated.name } });
|
||||
}
|
||||
@@ -65,7 +79,7 @@ export async function DELETE(
|
||||
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, household: { userId } } });
|
||||
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 });
|
||||
|
||||
Reference in New Issue
Block a user