Migrar backend a PostgreSQL + Node.js/Express con nuevas funcionalidades
Backend (water-api/): - Crear API REST completa con Express + TypeScript - Implementar autenticación JWT con refresh tokens - CRUD completo para: projects, concentrators, meters, gateways, devices, users, roles - Agregar validación con Zod para todas las entidades - Implementar webhooks para The Things Stack (LoRaWAN) - Agregar endpoint de lecturas con filtros y resumen de consumo - Implementar carga masiva de medidores via Excel (.xlsx) Frontend: - Crear cliente HTTP con manejo automático de JWT y refresh - Actualizar todas las APIs para usar nuevo backend - Agregar sistema de autenticación real (login, logout, me) - Agregar selector de tipo (LORA, LoRaWAN, Grandes) en concentradores y medidores - Agregar campo Meter ID en medidores - Crear modal de carga masiva para medidores - Agregar página de consumo con gráficas y filtros - Corregir carga de proyectos independiente de datos existentes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
133
water-api/src/routes/index.ts
Normal file
133
water-api/src/routes/index.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { Router } from 'express';
|
||||
|
||||
// Import all route files
|
||||
import authRoutes from './auth.routes';
|
||||
import projectRoutes from './project.routes';
|
||||
import meterRoutes from './meter.routes';
|
||||
import concentratorRoutes from './concentrator.routes';
|
||||
import gatewayRoutes from './gateway.routes';
|
||||
import deviceRoutes from './device.routes';
|
||||
import userRoutes from './user.routes';
|
||||
import roleRoutes from './role.routes';
|
||||
import ttsRoutes from './tts.routes';
|
||||
import readingRoutes from './reading.routes';
|
||||
import bulkUploadRoutes from './bulk-upload.routes';
|
||||
|
||||
// Create main router
|
||||
const router = Router();
|
||||
|
||||
/**
|
||||
* Mount all routes with proper prefixes
|
||||
*
|
||||
* Authentication routes:
|
||||
* - POST /auth/login - Authenticate user
|
||||
* - POST /auth/refresh - Refresh access token
|
||||
* - POST /auth/logout - Logout user
|
||||
* - GET /auth/me - Get current user profile
|
||||
*/
|
||||
router.use('/auth', authRoutes);
|
||||
|
||||
/**
|
||||
* Project routes:
|
||||
* - GET /projects - List all projects
|
||||
* - GET /projects/:id - Get project by ID
|
||||
* - GET /projects/:id/stats - Get project statistics
|
||||
* - POST /projects - Create project
|
||||
* - PUT /projects/:id - Update project
|
||||
* - DELETE /projects/:id - Delete project
|
||||
*/
|
||||
router.use('/projects', projectRoutes);
|
||||
|
||||
/**
|
||||
* Meter routes:
|
||||
* - GET /meters - List all meters
|
||||
* - GET /meters/:id - Get meter by ID
|
||||
* - GET /meters/:id/readings - Get meter readings
|
||||
* - POST /meters - Create meter
|
||||
* - PUT /meters/:id - Update meter
|
||||
* - DELETE /meters/:id - Delete meter
|
||||
*/
|
||||
router.use('/meters', meterRoutes);
|
||||
|
||||
/**
|
||||
* Concentrator routes:
|
||||
* - GET /concentrators - List all concentrators
|
||||
* - GET /concentrators/:id - Get concentrator by ID
|
||||
* - POST /concentrators - Create concentrator
|
||||
* - PUT /concentrators/:id - Update concentrator
|
||||
* - DELETE /concentrators/:id - Delete concentrator
|
||||
*/
|
||||
router.use('/concentrators', concentratorRoutes);
|
||||
|
||||
/**
|
||||
* Gateway routes:
|
||||
* - GET /gateways - List all gateways
|
||||
* - GET /gateways/:id - Get gateway by ID
|
||||
* - GET /gateways/:id/devices - Get gateway devices
|
||||
* - POST /gateways - Create gateway
|
||||
* - PUT /gateways/:id - Update gateway
|
||||
* - DELETE /gateways/:id - Delete gateway
|
||||
*/
|
||||
router.use('/gateways', gatewayRoutes);
|
||||
|
||||
/**
|
||||
* Device routes:
|
||||
* - GET /devices - List all devices
|
||||
* - GET /devices/:id - Get device by ID
|
||||
* - GET /devices/dev-eui/:devEui - Get device by DevEUI
|
||||
* - POST /devices - Create device
|
||||
* - PUT /devices/:id - Update device
|
||||
* - DELETE /devices/:id - Delete device
|
||||
*/
|
||||
router.use('/devices', deviceRoutes);
|
||||
|
||||
/**
|
||||
* User routes:
|
||||
* - GET /users - List all users (admin only)
|
||||
* - GET /users/:id - Get user by ID (admin or self)
|
||||
* - POST /users - Create user (admin only)
|
||||
* - PUT /users/:id - Update user (admin or self)
|
||||
* - DELETE /users/:id - Deactivate user (admin only)
|
||||
* - PUT /users/:id/password - Change password (self only)
|
||||
*/
|
||||
router.use('/users', userRoutes);
|
||||
|
||||
/**
|
||||
* Role routes:
|
||||
* - GET /roles - List all roles
|
||||
* - GET /roles/:id - Get role by ID with user count
|
||||
* - POST /roles - Create role (admin only)
|
||||
* - PUT /roles/:id - Update role (admin only)
|
||||
* - DELETE /roles/:id - Delete role (admin only)
|
||||
*/
|
||||
router.use('/roles', roleRoutes);
|
||||
|
||||
/**
|
||||
* TTS (The Things Stack) webhook routes:
|
||||
* - GET /webhooks/tts/health - Health check
|
||||
* - POST /webhooks/tts/uplink - Handle uplink messages
|
||||
* - POST /webhooks/tts/join - Handle join events
|
||||
* - POST /webhooks/tts/downlink/ack - Handle downlink acknowledgments
|
||||
*
|
||||
* Note: These routes use webhook secret verification instead of JWT auth
|
||||
*/
|
||||
router.use('/webhooks/tts', ttsRoutes);
|
||||
|
||||
/**
|
||||
* Reading routes:
|
||||
* - GET /readings - List all readings with filtering
|
||||
* - GET /readings/summary - Get consumption summary
|
||||
* - GET /readings/:id - Get reading by ID
|
||||
* - POST /readings - Create reading
|
||||
* - DELETE /readings/:id - Delete reading (admin only)
|
||||
*/
|
||||
router.use('/readings', readingRoutes);
|
||||
|
||||
/**
|
||||
* Bulk upload routes:
|
||||
* - POST /bulk-upload/meters - Upload Excel file with meters data
|
||||
* - GET /bulk-upload/meters/template - Download Excel template for meters
|
||||
*/
|
||||
router.use('/bulk-upload', bulkUploadRoutes);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user