Skip to content

Commit 3f31894

Browse files
deaths route
1 parent d279d78 commit 3f31894

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

routes/deaths.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const express = require('express');
2+
const get_data = require('../helpers/fetch-data');
3+
4+
const router = express.Router();
5+
6+
const url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv';
7+
8+
router.get('/', (req, res) => {
9+
// fetch the data
10+
get_data(url)
11+
.then(response => res.json(response));
12+
});
13+
14+
router.get('/:country', (req, res) => {
15+
// fetch the data
16+
get_data(url)
17+
.then(response => {
18+
19+
let countryData = {}
20+
// loop through all the countries
21+
response.forEach(country => {
22+
// for every country
23+
// if there is Country/Region is equal to passed country
24+
if (country['Country/Region'].toString().toLowerCase() === req.params.country.toLowerCase()) {
25+
countryData = country
26+
}
27+
})
28+
// send the country data back
29+
res.send(countryData);
30+
}).catch(e => console.log(e))
31+
});
32+
33+
module.exports = router;

0 commit comments

Comments
 (0)