@@ -0,0 +1,53 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user