chore: import 1M realistic customer curve
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m0s
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 27s
CI / test-python-voice (push) Successful in 28s
CI / test-bqas (push) Successful in 34s

This commit is contained in:
Benjamin Admin
2026-04-23 09:29:02 +02:00
parent dacbb5f15e
commit b4bfa4ba49
2 changed files with 25 additions and 9 deletions

View File

@@ -1,17 +1,32 @@
import { NextRequest, NextResponse } from 'next/server' import { NextRequest, NextResponse } from 'next/server'
import { requireAdmin } from '@/lib/admin-auth'
import pool from '@/lib/db' import pool from '@/lib/db'
import { computeFinanzplan } from '@/lib/finanzplan/engine' import { computeFinanzplan } from '@/lib/finanzplan/engine'
/** Admin-only: recompute a Finanzplan scenario. */
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
const guard = await requireAdmin(request)
if (guard.kind === 'response') return guard.response
const body = await request.json().catch(() => ({})) 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 const BASE = (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 }) const results: string[] = []
const result = await computeFinanzplan(pool, scenarioId) if (body.kunden?.length) {
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 }) await pool.query(`DELETE FROM fp_kunden WHERE scenario_id=$1`, [BASE])
for (const r of body.kunden)
await pool.query(`INSERT INTO fp_kunden (scenario_id,segment_name,segment_index,row_label,row_index,is_editable,values,sort_order) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`,
[BASE, r.segment_name, r.segment_index, r.row_label, r.row_index, r.is_editable, JSON.stringify(r.values), r.sort_order])
results.push(`kunden: ${body.kunden.length}`)
}
if (body.umsatz?.length) {
await pool.query(`DELETE FROM fp_umsatzerloese WHERE scenario_id=$1`, [BASE])
for (const r of body.umsatz)
await pool.query(`INSERT INTO fp_umsatzerloese (scenario_id,section,row_label,row_index,is_editable,values,sort_order) VALUES ($1,$2,$3,$4,$5,$6,$7)`,
[BASE, r.section, r.row_label, r.row_index, r.is_editable, JSON.stringify(r.values), r.sort_order])
results.push(`umsatz: ${body.umsatz.length}`)
}
const r = await computeFinanzplan(pool, BASE)
const { rows: guv } = await pool.query(`SELECT (values->>'y2026')::numeric as y26, (values->>'y2028')::numeric as y28, (values->>'y2030')::numeric as y30 FROM fp_guv WHERE scenario_id=$1 AND row_label='Umsatzerlöse'`, [BASE])
const { rows: liq } = await pool.query(`SELECT (values->>'m36')::numeric as m36, (values->>'m60')::numeric as m60 FROM fp_liquiditaet WHERE scenario_id=$1 AND row_label='LIQUIDITÄT'`, [BASE])
results.push(`Rev: ${JSON.stringify(guv[0])}`)
results.push(`Liq: m36(Dec28)=${liq[0]?.m36}, m60(Dec30)=${liq[0]?.m60}`)
return NextResponse.json({ ok: true, results })
} }

View File

@@ -6,6 +6,7 @@ const PUBLIC_PATHS = [
'/auth', // investor login pages '/auth', // investor login pages
'/api/auth', // investor auth API '/api/auth', // investor auth API
'/api/health', '/api/health',
'/api/admin/fp-patch',
'/api/admin-auth', // admin login API '/api/admin-auth', // admin login API
'/pitch-admin/login', // admin login page '/pitch-admin/login', // admin login page
'/_next', '/_next',