The Incident Reporting System is a Node.js application for managing incident reports for insurance clients. It allows users to submit incident reports with details such as description, city, and country, and integrates with an external weather API to fetch weather data for each incident. The system provides endpoints for creating, retrieving, and filtering incident reports.
- Submit new incident reports
- Retrieve incident reports by country
- Filter incident reports by city, temperature range, and humidity
- ...
- Node.js
- Express.js
- PostgreSQL
- Sequelize ORM
- OpenWeatherMap API
- Mocha and Chai for testing
-
Clone the repository:
git clone https://github.com/Joshua-png/Incident-Reporting.git
-
PostgreSQL server:
Run or install a local PostgreSQL server to have the ability to run tests on this project.
-
Install dependencies:
cd Incident-Reporting npm install
-
Set up environment variables:
Create a
.env
file in the root directory and add the following variables:PORT = PORT NODE_ENV = NODE_ENV DB_URL=postgres://username:password@hostname/databaseName OPENWEATHERMAP_API_KEY= OPENWEATHERMAP_API_KEY
Replace
username
,password
, andOPENWEATHERMAP_API_KEY
with your PostgreSQL credentials when deployed on render and OpenWeatherMap API key. -
Set up environment variables for test:
Create a
.env.test
file in the root directory and add the following variables:PORT = port NODE_ENV = test OPENWEATHERMAP_API_KEY= OPENWEATHERMAP_API_KEY DB_USERNAME_TEST=username DB_PASSWORD_TEST=password DB_HOST_TEST=host DB_PORT_TEST=dbport
Replace
username
,password
,OPENWEATHERMAP_API_KEY
,host
,dbport
with your PostgreSQL credentials from your local Postgres. -
Run tests:
Run this command once and then use the other whenever you want to run tests
npm run test:setup
after
npm run test
-
Start the server:
npm start / npm run dev
-
Access the application:
The application will be running at
http://localhost:3000
. -
Access the application online:
The application will be running at https://incident-reporting.onrender.com
-
Create a new incident report:
Send a POST request to
/api/v1/incidents
with the following JSON payload:{ "incident_desc": "Description of the incident", "city": "City Name", "country": "Country Name" }
-
Retrieve all incident reports by country:
Send a POST with a body contain the countryName request to
/api/v1/incidents
. -
Filter incident reports:
You can filter incident reports by appending query parameters to the endpoint:
/api/v1/incidents?city=CityName
/api/v1/incidents?temperature_max=temp_max&temperature_min=temp_min
/api/v1/incidents?humidity=humidity