This is an poplutation management api that enables one add locations and the number of residents in each location distributed by gender. This application is built using NodeJS, Express, Typescript and MongoDB
In order to run this project locally you would need to have:
- Node (Best to install v10.4.0). You can use NVM to install and manage node versions on your machine
- MongoDB (For this project I used a docker image of mongoDB.)
- Docker (if you plan to setup mongoDB to run in a docker image)
- Yarn - After installing node install Yarn globally by running
npm -g install yarn
You can run a docker image of mongo DB using docker run -p 27017:27017 mongo:3.4.20-jessie
This command will download the specified mongo image if it does not exist locally and run the image. For this case am running the image mongo:3.4.20-jessie
but you can get a list of mongo images here. The -p 27017:27017
specifies that the running image is being exposed on port 27017
- Clone the repository
git clone https://github.com/malmike/PopulationManagementSystem.git
- Enter the directory and install the project dependencies
cd PopulationManagementSystem yarn install
- Rename sample.env to .env
mv sample.env .env
- Start mongodb service.
- If you install mongodb locally run
If you require authentication
mongod
sudo mongod
- If you setup mongodb to run in docker then just ensure that the image is running
If the image is not running then run the command
docker container ls
docker run -p 27017:27017 mongo:3.4.20-jessie
DB_URI=mongodb://localhost:27017/population_management_system
- If you install mongodb locally run
- Starting the application
The development environment is setup to allow live reloading using nodemon
yarn start-dev
- You can access the application in the browser
The API uses swagger for documentation and this can be accessed at
http://localhost:1337
http://localhost:1337/api-docs/
To execute the applications tests run
yarn test
To execute tests with coverage run
yarn test-coverage
TYPE | API ENDPOINT | DESCRIPTION | HEADERS | PAYLOAD |
---|---|---|---|---|
POST | /registerUser | Creates a user or signs in a existing user | content-type: applicaton/json |
{ "email": "string", "password": "string } |
GET | /getUser | Gets logged in user | content-type: applicaton/json x-access-token: token |
|
POST | /addLocation | Add location | content-type: applicaton/json x-access-token: token |
{ "name": "string", } |
GET | /getLocations | Gets all locations | content-type: applicaton/json x-access-token: token |
|
GET | /getLocation?name="test" | Gets location test | content-type: applicaton/json x-access-token: token |
|
PUT | /addSubLocation?name="test" | Add sublocation to location test | content-type: applicaton/json x-access-token: token |
{ "sub_location_name": "string" } |
PUT | /deleteSubLocation?name="test" | Delete sublocation from location test | content-type: applicaton/json x-access-token: token |
{ "sub_location_name": "string" } |
POST | /addPopulationSize?name="test" | Add population size to location test | content-type: applicaton/json x-access-token: token |
{ "males": 0, "females": 0 } |
GET | /getPopulationSize?name="test" | Get population size from location test | content-type: applicaton/json x-access-token: token |
|
PUT | /updatePopulationSize="test" | Update population size of location test | content-type: applicaton/json x-access-token: token |
{ "males": 0, "females": 0 } |