Some checks failed
Build pitch-deck / build-and-push (push) Failing after 1m8s
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 32s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Successful in 32s
CI / Deploy (push) Failing after 4s
Full pitch versioning: 12 data tables versioned as JSONB snapshots, git-style parent chain (draft→commit→fork), per-investor assignment, side-by-side diff engine, version-aware /api/data + /api/financial-model. Bug fixes: FM editor [object Object] for JSONB arrays, admin scroll. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
84 lines
3.0 KiB
TypeScript
84 lines
3.0 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import pool from '@/lib/db'
|
|
import { getSessionFromCookie } from '@/lib/auth'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export async function GET() {
|
|
try {
|
|
// Check if investor has an assigned version
|
|
const session = await getSessionFromCookie()
|
|
let versionId: string | null = null
|
|
|
|
if (session) {
|
|
const inv = await pool.query(
|
|
`SELECT assigned_version_id FROM pitch_investors WHERE id = $1`,
|
|
[session.sub],
|
|
)
|
|
versionId = inv.rows[0]?.assigned_version_id || null
|
|
}
|
|
|
|
// If version assigned, load from pitch_version_data
|
|
if (versionId) {
|
|
const { rows } = await pool.query(
|
|
`SELECT table_name, data FROM pitch_version_data WHERE version_id = $1`,
|
|
[versionId],
|
|
)
|
|
const map: Record<string, unknown[]> = {}
|
|
for (const row of rows) {
|
|
map[row.table_name] = typeof row.data === 'string' ? JSON.parse(row.data) : row.data
|
|
}
|
|
return NextResponse.json({
|
|
company: (map.company || [])[0] || null,
|
|
team: map.team || [],
|
|
financials: map.financials || [],
|
|
market: map.market || [],
|
|
competitors: map.competitors || [],
|
|
features: map.features || [],
|
|
milestones: map.milestones || [],
|
|
metrics: map.metrics || [],
|
|
funding: (map.funding || [])[0] || null,
|
|
products: map.products || [],
|
|
})
|
|
}
|
|
|
|
// Fallback: read from base tables (backward compatible)
|
|
const client = await pool.connect()
|
|
try {
|
|
const [
|
|
companyRes, teamRes, financialsRes, marketRes, competitorsRes,
|
|
featuresRes, milestonesRes, metricsRes, fundingRes, productsRes,
|
|
] = await Promise.all([
|
|
client.query('SELECT * FROM pitch_company LIMIT 1'),
|
|
client.query('SELECT * FROM pitch_team ORDER BY sort_order'),
|
|
client.query('SELECT * FROM pitch_financials ORDER BY year'),
|
|
client.query('SELECT * FROM pitch_market ORDER BY id'),
|
|
client.query('SELECT * FROM pitch_competitors ORDER BY id'),
|
|
client.query('SELECT * FROM pitch_features ORDER BY sort_order'),
|
|
client.query('SELECT * FROM pitch_milestones ORDER BY sort_order'),
|
|
client.query('SELECT * FROM pitch_metrics ORDER BY id'),
|
|
client.query('SELECT * FROM pitch_funding LIMIT 1'),
|
|
client.query('SELECT * FROM pitch_products ORDER BY sort_order'),
|
|
])
|
|
|
|
return NextResponse.json({
|
|
company: companyRes.rows[0] || null,
|
|
team: teamRes.rows,
|
|
financials: financialsRes.rows,
|
|
market: marketRes.rows,
|
|
competitors: competitorsRes.rows,
|
|
features: featuresRes.rows,
|
|
milestones: milestonesRes.rows,
|
|
metrics: metricsRes.rows,
|
|
funding: fundingRes.rows[0] || null,
|
|
products: productsRes.rows,
|
|
})
|
|
} finally {
|
|
client.release()
|
|
}
|
|
} catch (error) {
|
|
console.error('Database query error:', error)
|
|
return NextResponse.json({ error: 'Failed to load pitch data' }, { status: 500 })
|
|
}
|
|
}
|