feat: RLA API v1.0.0 — API complète + exports + thème McKinsey
- 9 endpoints métier : synthese, alertes, en-service, en-cours, par-region, clotures, pilotage-proactif, matrice-risque - Exports PDF (tous rôles) / XLSX PPTX DOCX (superadmin) - services/calc.js : helpers normalisés partagés - services/export-pdf.js : PDF async PDFKit par vue - Thème McKinsey (#1C2B4B / bleu pétrole / gris sobre) - Boutons XLSX/DOCX front (superadmin uniquement) - BASEROW_API_URL → https://baserow.bolbol.tn/api/ - dotenv override: true Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* GET /api/en-service
|
||||
* Marchés actifs en service (non clôturés)
|
||||
*/
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getMarches } = require('../services/baserow');
|
||||
const { isCloture, normalizeMarche, parseNum } = require('../services/calc');
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const { region, entrepreneur, projet, nature, statut } = req.query;
|
||||
const regionFilter = req.regionFilter;
|
||||
|
||||
let rows = await getMarches();
|
||||
|
||||
// Uniquement non clôturés
|
||||
rows = rows.filter(r => !isCloture(r));
|
||||
|
||||
// Filtres
|
||||
if (regionFilter) rows = rows.filter(r => r.region === regionFilter);
|
||||
else if (region) rows = rows.filter(r => r.region === region);
|
||||
if (entrepreneur) rows = rows.filter(r => String(r.entrepreneur || '').toLowerCase().includes(entrepreneur.toLowerCase()));
|
||||
if (projet) rows = rows.filter(r => String(r.projet || '').toLowerCase().includes(projet.toLowerCase()));
|
||||
if (nature) rows = rows.filter(r => String(r.nature || '').toLowerCase().includes(nature.toLowerCase()));
|
||||
if (statut) rows = rows.filter(r => String(r.statut || '').toLowerCase().includes(statut.toLowerCase()));
|
||||
|
||||
const items = rows.map(normalizeMarche);
|
||||
|
||||
// Agrégats
|
||||
const totalBudget = rows.reduce((s, r) => s + parseNum(r.tot_marche ?? r.totmarche ?? r.montant), 0);
|
||||
const tauxList = items.map(r => r.taux_phy_raw).filter(v => v > 0);
|
||||
const tauxMoyen = tauxList.length
|
||||
? Math.round(tauxList.reduce((a, b) => a + b, 0) / tauxList.length * 10) / 10
|
||||
: 0;
|
||||
|
||||
res.json({
|
||||
count: items.length,
|
||||
budget_total_raw: totalBudget,
|
||||
taux_avancement_moyen: tauxMoyen,
|
||||
items,
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(502).json({ error: 'Erreur Baserow', detail: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user