import { NextRequest, NextResponse } from "next/server"; import { prisma } from "@/lib/db"; import { getOwnedPhase } from "@/lib/queries"; import { getCurrentUserId } from "@/lib/session"; import { touchScenario } from "@/lib/versioning-db"; import { cashTransitionSchema } from "@/lib/elements"; // Speichert den Cash-Entscheid beim UEBERGANG nach dieser Phase: 1:1 übernehmen oder // einmaliger Zufluss / einmalige Kosten (Roadmap Nr. 1). Cash ist kein FinancialElement, // deshalb liegt der Entscheid direkt an der Von-Phase. export async function PUT( request: NextRequest, { params }: { params: Promise<{ phaseId: string }> } ) { const userId = await getCurrentUserId(); if (!userId) return NextResponse.json({ error: "Nicht authentifiziert." }, { status: 401 }); const { phaseId } = await params; const phase = await getOwnedPhase(phaseId, userId); if (!phase) return NextResponse.json({ error: "Phase nicht gefunden." }, { status: 404 }); const body = await request.json(); const parsed = cashTransitionSchema.safeParse(body); if (!parsed.success) return NextResponse.json({ error: "Ungültige Eingabe." }, { status: 400 }); await prisma.phase.update({ where: { id: phase.id }, data: { cashTransition: parsed.data }, }); await touchScenario(phase.scenarioId, userId); return NextResponse.json({ ok: true }); }