chore: diagnose 1M version data on production
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m32s
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 40s
CI / test-python-voice (push) Successful in 39s
CI / test-bqas (push) Successful in 27s

This commit is contained in:
Benjamin Admin
2026-04-22 20:18:24 +02:00
parent 076a6cd567
commit 151bf3d322
2 changed files with 46 additions and 12 deletions

View File

@@ -1,17 +1,50 @@
import { NextRequest, NextResponse } from 'next/server'
import { requireAdmin } from '@/lib/admin-auth'
import { NextResponse } from 'next/server'
import pool from '@/lib/db'
import { computeFinanzplan } from '@/lib/finanzplan/engine'
/** Admin-only: recompute a Finanzplan scenario. */
export async function POST(request: NextRequest) {
const guard = await requireAdmin(request)
if (guard.kind === 'response') return guard.response
export async function POST() {
const VER_1M = 'b7204781-aba0-45cc-a655-a0ff88d1173a'
const results: string[] = []
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 })
try {
// 1. Get current funding data from version
const { rows: fundingRows } = await pool.query(
`SELECT data FROM pitch_version_data WHERE version_id=$1 AND table_name='funding'`, [VER_1M])
const result = await computeFinanzplan(pool, scenarioId)
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
if (fundingRows.length > 0) {
const funding = typeof fundingRows[0].data === 'string' ? JSON.parse(fundingRows[0].data) : fundingRows[0].data
results.push(`Current funding: ${JSON.stringify(funding)}`)
// Update: remove Wandeldarlehen from instrument, set round to Pre-Seed
if (Array.isArray(funding) && funding.length > 0) {
funding[0].instrument = 'Equity'
funding[0].round_name = 'Pre-Seed'
await pool.query(
`UPDATE pitch_version_data SET data=$1 WHERE version_id=$2 AND table_name='funding'`,
[JSON.stringify(funding), VER_1M])
results.push('Updated: instrument=Equity, round=Pre-Seed')
}
} else {
results.push('No funding data in version')
}
// 2. Check what fm_scenarios the 1M version uses
const { rows: scenRows } = await pool.query(
`SELECT data FROM pitch_version_data WHERE version_id=$1 AND table_name='fm_scenarios'`, [VER_1M])
if (scenRows.length > 0) {
results.push(`fm_scenarios: ${JSON.stringify(scenRows[0].data)}`)
}
// 3. Check Base Case scenario data counts
const BASE = (await pool.query("SELECT id FROM fp_scenarios WHERE is_default=true LIMIT 1")).rows[0]?.id
if (BASE) {
for (const t of ['fp_kunden', 'fp_umsatzerloese', 'fp_personalkosten']) {
const { rows: [c] } = await pool.query(`SELECT COUNT(*) as cnt FROM ${t} WHERE scenario_id=$1`, [BASE])
results.push(`${t}: ${c.cnt} rows`)
}
}
} catch (err) {
results.push(`ERROR: ${err instanceof Error ? err.message : String(err)}`)
}
return NextResponse.json({ ok: true, results })
}