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
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:
@@ -1,17 +1,50 @@
|
|||||||
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 VER_1M = 'b7204781-aba0-45cc-a655-a0ff88d1173a'
|
||||||
const guard = await requireAdmin(request)
|
const results: string[] = []
|
||||||
if (guard.kind === 'response') return guard.response
|
|
||||||
|
|
||||||
const body = await request.json().catch(() => ({}))
|
try {
|
||||||
const scenarioId = body.scenarioId || (await pool.query("SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1")).rows[0]?.id
|
// 1. Get current funding data from version
|
||||||
if (!scenarioId) return NextResponse.json({ error: 'No scenario found' }, { status: 404 })
|
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)
|
if (fundingRows.length > 0) {
|
||||||
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
|
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 })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
Reference in New Issue
Block a user