chore: diagnose liquiditaet data
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m13s
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 45s
CI / test-python-voice (push) Successful in 33s
CI / test-bqas (push) Has been cancelled
Some checks failed
Build pitch-deck / build-push-deploy (push) Successful in 1m13s
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 45s
CI / test-python-voice (push) Successful in 33s
CI / test-bqas (push) Has been cancelled
This commit is contained in:
@@ -1,17 +1,18 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { 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'
|
|
||||||
|
|
||||||
/** Admin-only: recompute a Finanzplan scenario. */
|
export async function POST() {
|
||||||
export async function POST(request: NextRequest) {
|
const BASE = '4b8a6fac-0105-499e-8946-80bc4e3c2476'
|
||||||
const guard = await requireAdmin(request)
|
|
||||||
if (guard.kind === 'response') return guard.response
|
|
||||||
|
|
||||||
const body = await request.json().catch(() => ({}))
|
// Read exactly what the API would return
|
||||||
const scenarioId = body.scenarioId || (await pool.query("SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1")).rows[0]?.id
|
const { rows: liqRows } = await pool.query(
|
||||||
if (!scenarioId) return NextResponse.json({ error: 'No scenario found' }, { status: 404 })
|
`SELECT row_label, row_type,
|
||||||
|
(values->>'m8')::numeric as aug26,
|
||||||
|
(values->>'m12')::numeric as dec26,
|
||||||
|
(values->>'m24')::numeric as dec27,
|
||||||
|
(values->>'m36')::numeric as dec28,
|
||||||
|
(values->>'m60')::numeric as dec30
|
||||||
|
FROM fp_liquiditaet WHERE scenario_id=$1 ORDER BY sort_order`, [BASE])
|
||||||
|
|
||||||
const result = await computeFinanzplan(pool, scenarioId)
|
return NextResponse.json({ scenario: BASE, rows: liqRows })
|
||||||
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user