security: re-secure fp-patch
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m5s
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 36s
CI / test-python-voice (push) Successful in 31s
CI / test-bqas (push) Successful in 33s
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m5s
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 36s
CI / test-python-voice (push) Successful in 31s
CI / test-bqas (push) Successful in 33s
This commit is contained in:
@@ -1,24 +1,17 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { requireAdmin } from '@/lib/admin-auth'
|
||||
import pool from '@/lib/db'
|
||||
import { computeFinanzplan } from '@/lib/finanzplan/engine'
|
||||
|
||||
export async function POST() {
|
||||
const BASE = (await pool.query("SELECT id FROM fp_scenarios WHERE is_default=true LIMIT 1")).rows[0]?.id
|
||||
/** Admin-only: recompute a Finanzplan scenario. */
|
||||
export async function POST(request: NextRequest) {
|
||||
const guard = await requireAdmin(request)
|
||||
if (guard.kind === 'response') return guard.response
|
||||
|
||||
// Marketing-Agentur: add 100k to 2027, 125k to 2028
|
||||
// Current: 2026=5k/mo, 2027=8333/mo (100k), 2028=16667/mo (200k)
|
||||
// New: 2027=8333+8333=16667/mo (200k), 2028=16667+10417=27083/mo (325k)
|
||||
const agentur: Record<string,number> = {}
|
||||
for (let m = 8; m <= 12; m++) agentur[`m${m}`] = 5000 // 2026: unchanged
|
||||
for (let m = 13; m <= 24; m++) agentur[`m${m}`] = 16667 // 2027: 200k/12
|
||||
for (let m = 25; m <= 36; m++) agentur[`m${m}`] = 27083 // 2028: 325k/12
|
||||
for (let m = 37; m <= 48; m++) agentur[`m${m}`] = 20000 // 2029: unchanged
|
||||
for (let m = 49; m <= 60; m++) agentur[`m${m}`] = 25000 // 2030: unchanged
|
||||
const body = await request.json().catch(() => ({}))
|
||||
const scenarioId = body.scenarioId || (await pool.query("SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1")).rows[0]?.id
|
||||
if (!scenarioId) return NextResponse.json({ error: 'No scenario found' }, { status: 404 })
|
||||
|
||||
await pool.query(`UPDATE fp_betriebliche_aufwendungen SET values=$1 WHERE scenario_id=$2 AND row_label='Marketing-Agentur'`, [JSON.stringify(agentur), BASE])
|
||||
|
||||
const r = await computeFinanzplan(pool, BASE)
|
||||
const { rows: liq } = await pool.query(`SELECT (values->>'m24')::numeric as dec27, (values->>'m36')::numeric as dec28, (values->>'m60')::numeric as dec30 FROM fp_liquiditaet WHERE scenario_id=$1 AND row_label='LIQUIDITÄT'`, [BASE])
|
||||
|
||||
return NextResponse.json({ ok: true, liq: liq[0] })
|
||||
const result = await computeFinanzplan(pool, scenarioId)
|
||||
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user