SPB Git

Repository Public

route.ts 3.0 KB 63 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Vrai-Prix8 * File             : src/app/api/cost/sources/route.ts9 * Module           : app10 * Repository       : https://git.spboucher.ai/vrai-prix11 * Created          : 2026-09-0812 * Last Modified    : 2026-09-0813 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Vrai-Prix — méthode du coût : registre des sources (licence, dernière synchro, volume).43import { NextResponse } from "next/server";44import { getCostDb } from "@/lib/cost/db";4546export const runtime = "nodejs";4748export function GET() {49  try {50    const d = getCostDb();51    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,52        (SELECT COUNT(*) FROM cost_item_prices p WHERE p.source_id=s.id) prices,53        (SELECT COUNT(*) FROM labour_rates l WHERE l.source_id=s.id) labour,54        (SELECT COUNT(*) FROM cost_raw_observations o WHERE o.source_id=s.id) raw55      FROM cost_sources s ORDER BY s.priority, s.name`).all();56    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();57    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();58    return NextResponse.json({ sources: rows, runs, indices });59  } catch (e) {60    return NextResponse.json({ error: (e as Error).message }, { status: 500 });61  }62}63
Files main
Menu

Theme