Reports Module Documentation - EML Backend
1. Introduction
The Reports module in EML Backend allows the generation and retrieval of system activity reports, including calls, messages, and sent notifications.
2. Code Structure
modules/reports/
├── reports.module.ts # Module definition
├── reports.controller.ts # HTTP Controller
├── reports.service.ts # Report generation logic
├── reports.repository.ts # Database access
├── dto/ # Data Transfer Objects (DTOs)
│ ├── create-report.dto.ts
│ ├── filter-report.dto.ts
├── entities/ # Database models
│ ├── report.entity.ts
3. Available Endpoints
3.1 Get Activity Report
GET /reports/activity - Generates a system activity report.
Request Example:
curl -X GET http://localhost:3000/reports/activity?startDate=2025-03-01&endDate=2025-03-03 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."
Response Example:
{
"totalCalls": 150,
"totalMessages": 320,
"totalNotifications": 200,
"mostActiveUser": "Juan Perez"
}
3.2 Generate Call Report
GET /reports/calls - Retrieves a detailed report of completed calls.
Request Example:
curl -X GET http://localhost:3000/reports/calls?startDate=2025-03-01&endDate=2025-03-03 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."
Response Example:
[
{
"callId": "abc123",
"clientId": "12345",
"agentId": "67890",
"status": "completed",
"duration": 320,
"timestamp": "2025-03-03T12:34:56Z"
}
]
3.3 Generate Message Report
GET /reports/messages - Retrieves a report of sent messages.
Request Example:
curl -X GET http://localhost:3000/reports/messages?startDate=2025-03-01&endDate=2025-03-03 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."
Response Example:
[
{
"messageId": "msg101",
"recipient": "+50312345678",
"message": "Hello, this is a test message.",
"status": "delivered",
"timestamp": "2025-03-03T12:34:56Z"
}
]
3.4 Export Reports in CSV Format
GET /reports/export - Generates a CSV file with report data.
Request Example:
curl -X GET http://localhost:3000/reports/export?type=calls&startDate=2025-03-01&endDate=2025-03-03 -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5c..."
Response Example:
A CSV file with report data will be downloaded.
4. Security and Middleware
- JWT Authentication: All requests require a valid JWT token.
- Data Filtering: Restrictions apply based on the user’s role.
- Query Optimization: Database indexing is used to improve response times.
Example of middleware for authorization:
@UseGuards(AuthGuard('jwt'), RolesGuard)
@Roles('admin')
@Get('activity')
async getActivityReport(@Query() filterDto: FilterReportDto) {
return this.reportService.getActivityReport(filterDto);
}
5. Dependencies with Other Modules
- Calls: To retrieve data on completed calls.
- Messages: To generate reports on sent messages.
- Notifications: To track sent notification metrics.
6. Additional Notes
- Plans to implement interactive dashboards and graphs with Grafana integration.
- Considering the possibility of generating reports in PDF format.
7. Conclusion
The Reports module in EML Backend facilitates the generation and analysis of system activity data, providing key metrics for platform management.
🚀 This document will be updated as the system evolves.