Files
FPT/src/app/api/plans/[planId]/route.ts
T
Damian Kellenberger 1e8f1772d9
Deploy App / deploy (push) Failing after 1m1s
First Commit
2026-07-08 00:13:32 +02:00

54 lines
1.5 KiB
TypeScript

import { NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { scenarioInclude } from "@/lib/scenario-service";
type Params = { params: Promise<{ planId: string }> };
export async function GET(_request: Request, { params }: Params) {
const { planId } = await params;
const plan = await prisma.plan.findUnique({
where: { id: planId },
include: {
scenarios: {
orderBy: { sortOrder: "asc" },
include: scenarioInclude,
},
},
});
if (!plan) {
return NextResponse.json({ error: "Plan nicht gefunden" }, { status: 404 });
}
return NextResponse.json(plan);
}
export async function PUT(request: Request, { params }: Params) {
const { planId } = await params;
const body = await request.json();
const plan = await prisma.plan.update({
where: { id: planId },
data: {
name: body.name,
householdType: body.householdType,
person1Name: body.person1Name,
person1CurrentAge: Number(body.person1CurrentAge),
person2Name: body.person2Name ?? null,
person2CurrentAge: body.person2CurrentAge
? Number(body.person2CurrentAge)
: null,
plannedRetirementAge: Number(body.plannedRetirementAge),
defaultInflationRate: Number(body.defaultInflationRate),
},
});
return NextResponse.json(plan);
}
export async function DELETE(_request: Request, { params }: Params) {
const { planId } = await params;
await prisma.plan.delete({ where: { id: planId } });
return NextResponse.json({ ok: true });
}