Gestion-des-Marches-RLA/README.md

141 lines
5.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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)
```