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'; import auditRoutes from './audit.routes'; import notificationRoutes from './notification.routes'; import testRoutes from './test.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); /** * Audit routes: * - GET /audit-logs - List all audit logs (admin only) * - GET /audit-logs/my-activity - Get current user's activity * - GET /audit-logs/statistics - Get audit statistics (admin only) * - GET /audit-logs/:id - Get audit log by ID (admin only) * - GET /audit-logs/record/:tableName/:recordId - Get logs for specific record (admin only) */ router.use('/audit-logs', auditRoutes); /** * Notification routes: * - GET /notifications - List user's notifications * - GET /notifications/unread-count - Get unread count * - GET /notifications/:id - Get notification by ID * - PATCH /notifications/:id/read - Mark notification as read * - PATCH /notifications/read-all - Mark all as read * - DELETE /notifications/:id - Delete notification */ router.use('/notifications', notificationRoutes); /** * Test routes (for development/testing only): * - POST /test/trigger-negative-flow - Manually trigger negative flow detection * - GET /test/negative-flow-meters - Get meters with negative flow * - GET /test/notifications-info - Get notifications system info */ if (process.env.NODE_ENV === 'development') { router.use('/test', testRoutes); } export default router;