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,140 @@
|
||||
# RLA API v1 — Marchés Tunisie Telecom Zone Sud
|
||||
|
||||
API REST + tableau de bord pour la gestion des marchés publics Tunisie Telecom Zone Sud.
|
||||
|
||||
**URL production :** `https://rla.bolbol.tn`
|
||||
|
||||
---
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
index.html → Front-end SPA (9 vues, thèmes, exports)
|
||||
server.js → Entry point Express (port 3005 par défaut)
|
||||
routes/ → Contrôleurs HTTP
|
||||
services/ → Logique métier (Baserow, calculs, exports)
|
||||
middleware/ → Auth JWT + RBAC
|
||||
data/users.json → Utilisateurs (bcrypt)
|
||||
logs/ → Logs connexion JSON
|
||||
```
|
||||
|
||||
## Endpoints API
|
||||
|
||||
### Public
|
||||
| Méthode | Endpoint | Description |
|
||||
|---------|----------|-------------|
|
||||
| GET | `/api/health` | Santé du service |
|
||||
| POST | `/api/auth/login` | Authentification → JWT |
|
||||
|
||||
### Données (auth requise)
|
||||
| Méthode | Endpoint | Description |
|
||||
|---------|----------|-------------|
|
||||
| GET | `/api/synthese` | KPIs globaux + alertes + pilotage |
|
||||
| GET | `/api/alertes` | Marchés avec alertes délai (≤90j) |
|
||||
| GET | `/api/en-service` | Marchés actifs en service |
|
||||
| GET | `/api/en-cours` | Marchés en cours (taux_phy < 100%) |
|
||||
| GET | `/api/par-region` | Agrégation par région |
|
||||
| GET | `/api/clotures` | Marchés clôturés |
|
||||
| GET | `/api/pilotage-proactif` | Niveaux avancement (normal/sous/dépassé) |
|
||||
| GET | `/api/matrice-risque` | Matrice risque 3×3 (délai × avancement) |
|
||||
| GET | `/api/marches` | Liste complète marchés |
|
||||
| GET | `/api/marches/:id` | Détail marché |
|
||||
| GET | `/api/stats` | Statistiques (compat. ancien front) |
|
||||
|
||||
### Exports (auth requise)
|
||||
| Méthode | Endpoint | Rôle min. | Description |
|
||||
|---------|----------|-----------|-------------|
|
||||
| GET | `/api/export/pdf?view=<vue>` | user | PDF par vue |
|
||||
| GET | `/api/export/xlsx?view=<vue>` | superadmin | Excel |
|
||||
| GET | `/api/export/pptx?view=<vue>` | superadmin | PowerPoint |
|
||||
| GET | `/api/export/docx?view=<vue>` | superadmin | Word |
|
||||
|
||||
**Vues disponibles :** `synthese`, `alertes`, `en-service`, `en-cours`, `par-region`, `clotures`, `pilotage`, `matrice-risque`
|
||||
|
||||
### Admin (superadmin)
|
||||
| Méthode | Endpoint | Description |
|
||||
|---------|----------|-------------|
|
||||
| GET | `/api/users` | Liste utilisateurs |
|
||||
| POST | `/api/users` | Créer utilisateur |
|
||||
| DELETE | `/api/users/:id` | Supprimer utilisateur |
|
||||
| GET | `/api/logs` | Logs connexion |
|
||||
| GET | `/api/pipeline` | Pipeline AO (admin+) |
|
||||
|
||||
## Paramètres de filtres
|
||||
|
||||
Tous les endpoints données acceptent :
|
||||
|
||||
| Paramètre | Type | Exemple |
|
||||
|-----------|------|---------|
|
||||
| `region` | string | `?region=Sfax` |
|
||||
| `entrepreneur` | string | `?entrepreneur=Ent%20X` |
|
||||
| `projet` | string | `?projet=4G` |
|
||||
| `nature` | string | `?nature=CAPEX` |
|
||||
| `statut` | string | `?statut=en+cours` |
|
||||
| `niveau` | string | `?niveau=critique` (alertes) |
|
||||
|
||||
## Variables d'environnement
|
||||
|
||||
| Variable | Requis | Description |
|
||||
|----------|--------|-------------|
|
||||
| `JWT_SECRET` | ✓ | Clé secrète JWT |
|
||||
| `BASEROW_API_URL` | ✓ | URL Baserow (`https://baserow.bolbol.tn/api/`) |
|
||||
| `BASEROW_TOKEN` | ✓ | Token d'accès Baserow |
|
||||
| `BASEROW_TABLE_MARCHES` | ✓ | ID table marchés (ex: 856) |
|
||||
| `BASEROW_TABLE_PIPELINE` | ✓ | ID table pipeline (ex: 872) |
|
||||
| `PORT` | — | Port serveur (défaut: 3001) |
|
||||
| `USERS` | — | JSON utilisateurs (init si data/users.json absent) |
|
||||
| `SEUIL_STANDARD` | — | Seuil avancement normal (défaut: 70) |
|
||||
| `SEUIL_CRITIQUE_PCT` | — | Seuil avancement critique (défaut: 90) |
|
||||
| `DELAI_CRITIQUE` | — | Jours alerte critique (défaut: 45) |
|
||||
| `DELAI_ATTENTION` | — | Jours alerte attention (défaut: 90) |
|
||||
|
||||
## Rôles
|
||||
|
||||
| Rôle | PDF | PPTX/XLSX/DOCX | Pipeline | Users | Logs |
|
||||
|------|-----|----------------|----------|-------|------|
|
||||
| user | ✓ | ✗ | ✗ | ✗ | ✗ |
|
||||
| admin | ✓ | ✗ | ✓ | ✗ | ✗ |
|
||||
| superadmin | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||
|
||||
## Démarrage
|
||||
|
||||
```bash
|
||||
npm install
|
||||
cp .env.example .env # configurer les variables
|
||||
npm start # production
|
||||
npm run dev # développement (--watch)
|
||||
```
|
||||
|
||||
## Structure des fichiers
|
||||
|
||||
```
|
||||
routes/
|
||||
auth.js → POST /api/auth/login
|
||||
marches.js → GET /api/marches[/:id]
|
||||
stats.js → GET /api/stats
|
||||
synthese.js → GET /api/synthese
|
||||
alertes.js → GET /api/alertes
|
||||
en-service.js → GET /api/en-service
|
||||
en-cours.js → GET /api/en-cours
|
||||
par-region.js → GET /api/par-region
|
||||
clotures.js → GET /api/clotures
|
||||
pilotage.js → GET /api/pilotage-proactif
|
||||
matrice-risque.js → GET /api/matrice-risque
|
||||
export.js → GET /api/export/[pdf|xlsx|pptx|docx]
|
||||
pipeline.js → GET /api/pipeline
|
||||
users.js → CRUD /api/users
|
||||
logs.js → GET /api/logs
|
||||
|
||||
services/
|
||||
baserow.js → Client Baserow (pagination auto)
|
||||
calc.js → Calculs métier (alertes, risques, formatage)
|
||||
export-pdf.js → Générateurs PDF par vue (PDFKit)
|
||||
export-xlsx.js → Générateur Excel (ExcelJS)
|
||||
users.js → CRUD fichier users.json
|
||||
logs.js → Logs connexion JSON
|
||||
|
||||
middleware/
|
||||
auth.js → Vérification JWT Bearer
|
||||
roles.js → RBAC (requireUser/Admin/SuperAdmin + filterByRegion)
|
||||
```
|
||||
Reference in New Issue
Block a user