Repository Public
1// Vrai-Prix — méthode du coût : registre des sources (licence, dernière synchro, volume).2import { NextResponse } from "next/server";3import { getCostDb } from "@/lib/cost/db";45export const runtime = "nodejs";67export function GET() {8 try {9 const d = getCostDb();10 const rows = d.prepare(`SELECT s.key, s.name, s.source_type type, s.base_url url, s.jurisdiction, s.license_status license, s.license_notes notes, s.terms_url, s.is_active active, s.priority, s.quality, s.refresh_frequency frequency, s.last_successful_sync lastSync, s.last_error lastError,11 (SELECT COUNT(*) FROM cost_item_prices p WHERE p.source_id=s.id) prices,12 (SELECT COUNT(*) FROM labour_rates l WHERE l.source_id=s.id) labour,13 (SELECT COUNT(*) FROM cost_raw_observations o WHERE o.source_id=s.id) raw14 FROM cost_sources s ORDER BY s.priority, s.name`).all();15 const runs = d.prepare("SELECT connector, status, started_at, finished_at, observations, accepted, rejected, unchanged, errors FROM connector_runs ORDER BY started_at DESC LIMIT 30").all();16 const indices = d.prepare("SELECT index_code code, geography, building_type, division, MAX(period) last, COUNT(*) n FROM construction_cost_indices GROUP BY index_code").all();17 return NextResponse.json({ sources: rows, runs, indices });18 } catch (e) {19 return NextResponse.json({ error: (e as Error).message }, { status: 500 });20 }21}22