import { NextResponse } from 'next/server'; import { getCatalogMeta, syncCatalog } from '@/lib/firm-catalog'; import { getClients, reconcileClients } from '@/lib/clients'; import { resolveFirmAssignments } from '@/lib/account-type-resolver'; import { getSetting } from '@/lib/db'; /** Sync status for the Settings page. */ export async function GET() { return NextResponse.json({ ...getCatalogMeta(), masterUrl: getSetting('master_dashboard_url'), }); } /** Force a pull now, instead of waiting for the poll. */ export async function POST() { const result = await syncCatalog(); if (result.changed) { reconcileClients(); for (const [firmId, client] of getClients()) { try { resolveFirmAssignments(firmId, client); } catch (err) { console.error(`[resolver] re-resolve failed for ${firmId}`, err); } } } return NextResponse.json({ ...result, ...getCatalogMeta() }); }