Emergency Management API Documentation
Emergency Management API Documentation
Introduction
This document provides detailed information about the Emergency Management API. The
API enables CRUD operations on emergency entities including user and authentication
handling. Below is a breakdown of the available endpoints and their functionalities.
Base URL
/admin/emergency
Endpoints
1. Create Emergency
Method: POST
URL: /emergencySignup
Description:
Request Body:
"type": "hospital",
"phone": "1234567890",
"number": "102",
"latitude": 29.9792,
"longitude": 31.1342 }
Validation Rules:
Response:
• Success (201):
"status": "success",
"data": {
"id": "<generated-id>",
"type": "hospital",
"phone": "1234567890",
"number": "102",
"latitude": 29.9792,
"longitude": 31.1342
"status": "failed",
"errors": [{ "msg": "Phone must be numeric." }]
Method: GET
URL: /emergency
Description:
Response:
• Success (200):
{
"status": "success",
"data": [
{
"id": "1",
"type": "hospital",
"name": "City Hospital",
"phone": "1234567890",
"address": "123 Main St",
"number": "102",
"latitude": 29.9792,
"longitude": 31.1342
} ] }
• No Data Found (404):
{
"status": "failed",
"errors": [{ "msg": "No data found." }]
}
3. Get Emergency by ID
Fetches details of a specific emergency by its unique ID.
• Method: GET
• Endpoint: /api/emergency/:id
• Parameters:
Sample Response:
{
"status": "success",
"data": [ { "id": "123", "name": "Fire Brigade", "type": "fire", ... } ]
}
"status": "failed",
4. Update Emergency
Method: PUT
URL: /emergency/:id
Description:
Updates an existing emergency record. Validates that all provided fields are unique and that
the body contains new data to update.
Request Body:
"type": "hospital",
"phone": "1234567890"
Validation Rules:
Response:
• Success (200):
{
"status": "success",
"msg": "Emergency updated successfully.",
"data": {
"type": "hospital",
"name": "City Hospital",
"phone": "1234567890",
"updatedAt": "<timestamp>"
}
}
{
"status": "success",
"msg": "No new data to update."
}
"status": "failed",
"errors": [
5. Delete Emergency
Method: DELETE
URL: /emergency/:id
Description:
• Success (200):
"status": "success",
"status": "failed",
"status": "failed",
Error Handling
• Validation Errors: Each request is validated against specific rules, and validation
errors are returned in a structured format with error messages.
• 404 Errors: Returned when requested data is not found.
• 500 Errors: Returned for unexpected server errors.
Notes
1. All endpoints are protected and require authentication using the admin token.
2. Use the adminProtect middleware for routes to ensure authorization.
3. Fields like email, phone, and number must be unique across all records.