feat: Add Emergency Calls Service with Complete API and Analytics#8
Open
feat: Add Emergency Calls Service with Complete API and Analytics#8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
Implements a comprehensive emergency calls service for SAMU data analysis, including database schema, API endpoints, analytics, and full test coverage.
🚀 Features Added
🗄️ Database & Schema
New emergency_calls table with 103k+ records from SAMU data
Comprehensive schema with fields for accidents, demographics, and locations
Automated data seeding from TSV file with proper type conversions
Database validation queries for data quality assurance
🔌 RESTful API
Calls endpoints: List, filter, and retrieve individual emergency calls
Analytics endpoints: Municipality stats, accident types, gender distribution, dangerous streets
Full pagination, filtering, and sorting support
OpenAPI documentation with interactive interface
📊 Analytics Features
Municipality-based emergency call statistics
Accident type distribution analysis
Gender and age demographic breakdowns
Most dangerous streets identification
Temporal analysis capabilities
🧪 Testing & Quality
Comprehensive test suite covering all endpoints
Database integration tests with proper isolation
Error handling and edge case validation
Code quality checks (lint, format, type-check)
📁 Files Added
apps/emergency-calls/
├── src/
│ ├── db/ # Database layer
│ ├── routes/ # API endpoints
│ │ ├── calls/ # Emergency calls CRUD
│ │ └── analytics/ # Analytics endpoints
│ ├── lib/ # Shared utilities
│ └── middlewares/ # Request middleware
├── test/ # Test suite
├── Dockerfile # Container setup
└── package.json # Dependencies & scripts
packages/database/
└── src/schemas/emergency-calls/ # Shared database schema
Copy
🛠️ Technical Implementation
Database Schema
Nullable fields for incomplete data handling
Proper indexing for query performance
Zod validation schemas for type safety
Shared schema package for reusability
API Architecture
Route-handler separation pattern
OpenAPI specification generation
Structured error handling
Request/response validation
Data Processing
Batch processing for large datasets (100 records/batch)
Type conversion handling (strings → integers, dates)
Null value management for incomplete records
Performance optimized queries
📈 API Endpoints
Calls
GET /v1/calls - List calls with filtering
GET /v1/calls/{id} - Get specific call details
Analytics
GET /v1/analytics/municipalities - Municipality statistics
GET /v1/analytics/accident-types - Accident type distribution
GET /v1/analytics/gender-distribution - Gender demographics
GET /v1/analytics/dangerous-streets - Most dangerous locations
🔧 Commands
Development
pnpm --filter @atlas/emergency-calls dev
Database
pnpm --filter @atlas/emergency-calls db:seed
Testing
pnpm --filter @atlas/emergency-calls test
Documentation
pnpm --filter @atlas/emergency-calls generate-openapi
Copy
bash
📚 Documentation
Complete API documentation at /docs/?api=emergency-calls-api
Database validation queries included
Comprehensive README with usage examples
Updated manual database setup guide
✅ Quality Assurance
All tests passing
Code quality checks passed
OpenAPI specification generated
Database properly seeded and validated
CI/CD integration ready
Ready for review and deployment 🚀