import { NextResponse } from 'next/server' import { getSession } from '@/lib/auth' import { getActiveDocuments, getPendingAcceptances } from '@/lib/legal' // GET: aktive Rechtsdokumente + offene Pflicht-Zustimmungen des aktuellen Benutzers. // Grundlage für den blockierenden Re-Consent-Dialog. export async function GET() { try { const user = await getSession() if (!user) return NextResponse.json({ error: 'Nicht autorisiert' }, { status: 401 }) const isOrgAdmin = user.role === 'TENANT_ADMIN' const [active, pending] = await Promise.all([ getActiveDocuments(), getPendingAcceptances(user.id, isOrgAdmin), ]) return NextResponse.json({ isOrgAdmin, organizationId: user.tenantId ?? null, documents: active, pending, // leer = alles akzeptiert needsAcceptance: pending.length > 0, }) } catch (error) { console.error('Error fetching legal status:', error) return NextResponse.json({ error: 'Serverfehler' }, { status: 500 }) } }