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>
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { prisma } from "@/lib/db";
|
|
import { getCurrentUserId } from "@/lib/session";
|
|
|
|
const personSchema = z.object({
|
|
role: z.enum(["PERSON_A", "PERSON_B"]),
|
|
age: z.number().int().min(0).max(120),
|
|
retirementAge: z.number().int().min(30).max(100),
|
|
});
|
|
|
|
// Ein Plan traegt sein eigenes Grundprofil (Haushaltsform, Personen, Inflation).
|
|
export const planProfileSchema = z.object({
|
|
householdType: z.enum(["SINGLE", "COUPLE"]),
|
|
inflationRateDefault: z.number().min(-20).max(50),
|
|
persons: z.array(personSchema).min(1).max(2),
|
|
});
|
|
|
|
const createPlanSchema = z
|
|
.object({ name: z.string().min(1).max(120) })
|
|
.and(planProfileSchema);
|
|
|
|
export function validatePersonsForType(data: z.infer<typeof planProfileSchema>): string | null {
|
|
if (data.householdType === "SINGLE" && data.persons.length !== 1) {
|
|
return "Einzelperson-Plan benoetigt genau eine Person.";
|
|
}
|
|
if (data.householdType === "COUPLE" && data.persons.length !== 2) {
|
|
return "Paar-Plan benoetigt genau zwei Personen (Person A und Person B).";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function GET() {
|
|
const userId = await getCurrentUserId();
|
|
if (!userId) {
|
|
return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
|
}
|
|
const plans = await prisma.plan.findMany({
|
|
where: { userId },
|
|
orderBy: { createdAt: "asc" },
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
parentPlanId: true,
|
|
branchFromPhaseId: true,
|
|
createdAt: true,
|
|
phases: {
|
|
select: { id: true, name: true, sequenceNumber: true },
|
|
orderBy: { sequenceNumber: "asc" },
|
|
},
|
|
},
|
|
});
|
|
return NextResponse.json({ plans });
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const userId = await getCurrentUserId();
|
|
if (!userId) {
|
|
return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 });
|
|
}
|
|
|
|
const body = await request.json();
|
|
const parsed = createPlanSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
|
}
|
|
const error = validatePersonsForType(parsed.data);
|
|
if (error) return NextResponse.json({ error }, { status: 400 });
|
|
|
|
const plan = await prisma.plan.create({
|
|
data: {
|
|
userId,
|
|
name: parsed.data.name,
|
|
householdType: parsed.data.householdType,
|
|
inflationRateDefault: parsed.data.inflationRateDefault,
|
|
persons: { create: parsed.data.persons },
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ plan: { id: plan.id } }, { status: 201 });
|
|
}
|