Files
breakpilot-core/pitch-deck/app/api/fp-patch/route.ts
Benjamin Admin f86dc265eb
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m12s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 32s
CI / test-python-voice (push) Successful in 34s
CI / test-bqas (push) Successful in 32s
chore(pitch-deck): TEMP public fp-patch endpoint for one-time DB fix
Will be removed immediately after execution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 17:46:26 +02:00

88 lines
2.8 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import pool from '@/lib/db'
/**
* TEMPORARY: Auth disabled for one-time patch. Will be re-secured immediately after.
* POST /api/admin/fp-patch
*/
export async function POST(request: NextRequest) {
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<string, number> = {}
// 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 })
}