Mini Project for AsmaraKu Internship
As per the mini project requirement given in the email. The mini project has been implemented with
-
HTTP API to get the data that has been put to the server, and also updates the data
GET /
to get all of the data points,GET /latest
to get just the latest data, andPOST /update
to update the data in the database -
Updates from COVID public API (in this case from covid19.go.id)
-
Automatically updates the data at 11:59 PM everyday, and if the data has changed (implemented by checking the date) to add it as data point
p.s. Also it will update the existing data if there are changes to the numbers, as Covid data could change even in one day
To try and run the application, I recommend to use docker compose for easy setup of the databse, follow these steps
-
Start the database with docker compose with
docker-compose up
-
Install all the dependencies using
yarn
yarn
-
Run the
init:db
script to add the required collectionyarn init:db
-
Add
.env
to configure the database connection stringsWhile the server will default use the local mongodb database, it is better to point it out to the right databae. So make
.env
file in the root of the project and fill it up with the following content.MONGO_CONNECTION_STRING=mongodb://localhost:27017/covid
-
Start the application
yarn start
In this part, it will be shown the time, described the challenges, and resources I used working on part A and B of the mini project.
Starts at 08:34 21 April 2022 and is done at 11:07 21 April 2022 with duration of 2 hours and 33 minutes.
Here are a few challenges I found while working at the Part A of the project
- I usually use more modern version of Javascript (ES2020 upwards), so there are a few challenges adapting back into the old Promise-based API. Especially on awaits function, so I used
async_polyfill
to polyfill some function that I make with async-await API methodology. - First I was trying to use the new feture of MongoDB, time series collection, but turns out it does not allow for update with query into it's
timeField
(see docs). So I had to remake theinitDb
script to just use the regular collection, but with the same data model, and I've added index into thetimeField
(attributetimestamp
) because it will be used a lot for query key.
Here are the resources I use while making this part of the mini-project
- Express.js Project Structure (github)
- MongoDB node driver (documentation)
- MongoDB Docker Image (docker hub)
- Async Polyfill Function (githib)
Starts at 11:35 21 April 2022 and is done at 11:59 21 April 2022 with duration of 24 minutes.
Here are a few challenges I found while working at the Part B of the project
- I was wondering how to do testing on function that will run at a specific time, so I set the time of trigger 5 seconds after it ran, and see how it runs.
- Also to test that the
updateOne
command from MongoDB runs as it should, I change the value of the metadata manually and see if it changes with the real data from the API. And surely it does updates it to the real data gathered from the API.
Here are the resources I use while making this part of the mini-project
- Bree Documentation (used for scheduling, documentation)