From 855e7649119e94eb1c519ee38c4f2d1929b3659d Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Mon, 20 Apr 2026 20:31:27 +0200 Subject: [PATCH] feat(pitch-deck): add fp-patch admin endpoint for insurance cost halving One-time endpoint to halve D&O, E&O, Produkthaftpflicht, Cyber, Rechtsschutz for 2027 and delete Editorial Content row. Co-Authored-By: Claude Opus 4.6 (1M context) --- pitch-deck/app/api/admin/fp-patch/route.ts | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 pitch-deck/app/api/admin/fp-patch/route.ts diff --git a/pitch-deck/app/api/admin/fp-patch/route.ts b/pitch-deck/app/api/admin/fp-patch/route.ts new file mode 100644 index 0000000..5581b1c --- /dev/null +++ b/pitch-deck/app/api/admin/fp-patch/route.ts @@ -0,0 +1,90 @@ +import { NextRequest, NextResponse } from 'next/server' +import { requireAdmin } from '@/lib/admin-auth' +import pool from '@/lib/db' + +/** + * One-time patch endpoint for Finanzplan data corrections. + * POST /api/admin/fp-patch + */ +export async function POST(request: NextRequest) { + const guard = await requireAdmin(request) + if (guard.kind === 'response') return guard.response + + const results: string[] = [] + + // 1. Halve insurance costs for 2027 (months m13-m24) + const insuranceLabels = [ + 'D&O-Versicherung', + 'E&O-Versicherung', + 'Produkthaftpflicht', + 'Cyber-Versicherung', + 'Rechtsschutzversicherung', + ] + + for (const label of insuranceLabels) { + try { + // Get the row + const { rows } = await pool.query( + `SELECT id, row_label, values FROM fp_betriebliche_aufwendungen + WHERE row_label = $1 + AND scenario_id = (SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1)`, + [label] + ) + if (rows.length === 0) { + // Try partial match + const { rows: partial } = await pool.query( + `SELECT id, row_label, values FROM fp_betriebliche_aufwendungen + WHERE row_label ILIKE $1 + AND scenario_id = (SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1)`, + [`%${label}%`] + ) + if (partial.length === 0) { + results.push(`NOT FOUND: ${label}`) + continue + } + rows.push(...partial) + } + + for (const row of rows) { + const values = row.values || {} + const updates: Record = {} + + // 2027 = months m13 to m24 + for (let m = 13; m <= 24; m++) { + const key = `m${m}` + const current = values[key] || 0 + if (current > 0) { + updates[key] = Math.round(current / 2) + } + } + + if (Object.keys(updates).length > 0) { + const newValues = { ...values, ...updates } + await pool.query( + 'UPDATE fp_betriebliche_aufwendungen SET values = $1, updated_at = NOW() WHERE id = $2', + [JSON.stringify(newValues), row.id] + ) + results.push(`HALVED 2027: ${row.row_label} (id=${row.id})`) + } else { + results.push(`NO VALUES 2027: ${row.row_label}`) + } + } + } catch (err) { + results.push(`ERROR ${label}: ${err instanceof Error ? err.message : String(err)}`) + } + } + + // 2. Delete "Editorial Content" row + try { + const { rowCount } = await pool.query( + `DELETE FROM fp_betriebliche_aufwendungen + WHERE row_label ILIKE '%Editorial Content%' + AND scenario_id = (SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1)` + ) + results.push(`DELETED Editorial Content: ${rowCount} row(s)`) + } catch (err) { + results.push(`ERROR deleting Editorial Content: ${err instanceof Error ? err.message : String(err)}`) + } + + return NextResponse.json({ success: true, results }) +}