fix: tab row counts use investor's scenario, not always Base Case
Build pitch-deck / build-push-deploy (push) Successful in 1m34s
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 36s
CI / test-python-voice (push) Successful in 35s
CI / test-bqas (push) Successful in 32s
Build pitch-deck / build-push-deploy (push) Successful in 1m34s
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 36s
CI / test-python-voice (push) Successful in 35s
CI / test-bqas (push) Successful in 32s
/api/finanzplan now accepts ?scenarioId and uses it for the per-sheet row counts (the numbers in brackets on the tab bar). FinanzplanSlide passes fpBaseScenarioId when fetching the sheet list, so Wandeldarlehen investors see e.g. Personalkosten (9) instead of (35). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,23 +3,31 @@ import pool from '@/lib/db'
|
|||||||
import { SHEET_LIST } from '@/lib/finanzplan/types'
|
import { SHEET_LIST } from '@/lib/finanzplan/types'
|
||||||
|
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
// Only expose scenario list to admin callers (bearer token)
|
// Only expose full scenario list to admin callers (bearer token)
|
||||||
const secret = process.env.PITCH_ADMIN_SECRET
|
const secret = process.env.PITCH_ADMIN_SECRET
|
||||||
const auth = request.headers.get('authorization') ?? ''
|
const auth = request.headers.get('authorization') ?? ''
|
||||||
const isAdmin = secret && auth === `Bearer ${secret}`
|
const isAdmin = secret && auth === `Bearer ${secret}`
|
||||||
|
|
||||||
|
// Allow callers to pass a scenarioId for row counts (e.g. investor's assigned scenario)
|
||||||
|
const scenarioId = request.nextUrl.searchParams.get('scenarioId')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Investors see only the default scenario — no names of other scenarios leaked
|
// Investors see only the default scenario — no names of other scenarios leaked
|
||||||
const scenarios = isAdmin
|
const scenarios = isAdmin
|
||||||
? await pool.query('SELECT * FROM fp_scenarios ORDER BY is_default DESC, name')
|
? await pool.query('SELECT * FROM fp_scenarios ORDER BY is_default DESC, name')
|
||||||
: await pool.query('SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1')
|
: await pool.query('SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1')
|
||||||
|
|
||||||
// Get row counts per sheet
|
// Get row counts per sheet using the caller's scenario
|
||||||
const sheets = await Promise.all(
|
const sheets = await Promise.all(
|
||||||
SHEET_LIST.map(async (s) => {
|
SHEET_LIST.map(async (s) => {
|
||||||
const tableName = `fp_${s.name}`
|
const tableName = `fp_${s.name}`
|
||||||
try {
|
try {
|
||||||
const { rows } = await pool.query(
|
const { rows } = scenarioId
|
||||||
|
? await pool.query(
|
||||||
|
`SELECT COUNT(*) as total, COUNT(*) FILTER (WHERE is_editable = true) as editable FROM ${tableName} WHERE scenario_id = $1`,
|
||||||
|
[scenarioId]
|
||||||
|
)
|
||||||
|
: await pool.query(
|
||||||
`SELECT COUNT(*) as total, COUNT(*) FILTER (WHERE is_editable = true) as editable FROM ${tableName} WHERE scenario_id = (SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1)`
|
`SELECT COUNT(*) as total, COUNT(*) FILTER (WHERE is_editable = true) as editable FROM ${tableName} WHERE scenario_id = (SELECT id FROM fp_scenarios WHERE is_default = true LIMIT 1)`
|
||||||
)
|
)
|
||||||
return { ...s, rows: parseInt(rows[0]?.total || '0'), editable_rows: parseInt(rows[0]?.editable || '0') }
|
return { ...s, rows: parseInt(rows[0]?.total || '0'), editable_rows: parseInt(rows[0]?.editable || '0') }
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ export default function FinanzplanSlide({ lang, investorId, preferredScenarioId,
|
|||||||
|
|
||||||
// Load sheet list; populate scenario selector from version data or API fallback
|
// Load sheet list; populate scenario selector from version data or API fallback
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch('/api/finanzplan', { cache: 'no-store' })
|
const listParam = fpBaseScenarioId ? `?scenarioId=${fpBaseScenarioId}` : ''
|
||||||
|
fetch(`/api/finanzplan${listParam}`, { cache: 'no-store' })
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
setSheets(data.sheets || [])
|
setSheets(data.sheets || [])
|
||||||
|
|||||||
Reference in New Issue
Block a user