security: re-secure fp-patch
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m10s
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 34s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Successful in 30s
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m10s
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 34s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Successful in 30s
This commit is contained in:
@@ -1,45 +1,17 @@
|
|||||||
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 WD = 'c0000000-0000-0000-0000-000000000200'
|
const guard = await requireAdmin(request)
|
||||||
const results: string[] = []
|
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
|
||||||
|
if (!scenarioId) return NextResponse.json({ error: 'No scenario found' }, { status: 404 })
|
||||||
|
|
||||||
try {
|
const result = await computeFinanzplan(pool, scenarioId)
|
||||||
// Insert betriebliche rows from body
|
return NextResponse.json({ success: true, scenarioId, cash_m60: result.liquiditaet?.endstand?.m60 })
|
||||||
if (body.betrieb) {
|
|
||||||
for (const [cat, label, vals, sort] of body.betrieb) {
|
|
||||||
const { rows } = await pool.query(`SELECT id FROM fp_betriebliche_aufwendungen WHERE scenario_id=$1 AND row_label=$2`, [WD, label])
|
|
||||||
if (rows.length === 0) {
|
|
||||||
await pool.query(`INSERT INTO fp_betriebliche_aufwendungen (scenario_id,category,row_label,row_index,is_editable,is_sum_row,values,sort_order) VALUES ($1,$2,$3,$4,true,false,$5,$4)`, [WD, cat, label, sort, JSON.stringify(vals)])
|
|
||||||
results.push(`ADD ${label}`)
|
|
||||||
} else {
|
|
||||||
results.push(`SKIP ${label} (exists)`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert liquidität rows from body
|
|
||||||
if (body.liq) {
|
|
||||||
for (const [label, vals] of body.liq) {
|
|
||||||
const { rows } = await pool.query(`SELECT id FROM fp_liquiditaet WHERE scenario_id=$1 AND row_label=$2`, [WD, label])
|
|
||||||
if (rows.length === 0) {
|
|
||||||
await pool.query(`INSERT INTO fp_liquiditaet (scenario_id,row_label,row_type,is_editable,values,sort_order) VALUES ($1,$2,'einzahlung',true,$3,3)`, [WD, label, JSON.stringify(vals)])
|
|
||||||
results.push(`ADD liq: ${label}`)
|
|
||||||
} else {
|
|
||||||
results.push(`SKIP liq: ${label} (exists)`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recompute
|
|
||||||
const r = await computeFinanzplan(pool, WD)
|
|
||||||
results.push(`WD cash_m60=${r.liquiditaet?.endstand?.m60}`)
|
|
||||||
} catch (err) {
|
|
||||||
results.push(`ERROR: ${err instanceof Error ? err.message : String(err)}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.json({ ok: true, results })
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ 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