File tree Expand file tree Collapse file tree 1 file changed +27
-9
lines changed Expand file tree Collapse file tree 1 file changed +27
-9
lines changed Original file line number Diff line number Diff line change 1
- const get_data = require ( '../helpers/fetch-data' ) ;
1
+ const express = require ( 'express' ) ;
2
+ const get_combined_data = require ( '../helpers/combined-data' ) ;
2
3
3
- const casesUrl = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'
4
- const recoveredUrl = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv' ;
5
- const deathsUrl = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv' ;
4
+ const router = express . Router ( ) ;
6
5
6
+ router . get ( '/' , ( req , res ) => {
7
+ // fetch the data
8
+ get_combined_data ( )
9
+ . then ( response => res . json ( response ) ) ;
10
+ } ) ;
7
11
8
- Promise . all ( [ get_data ( casesUrl ) , get_data ( recoveredUrl ) , get_data ( deathsUrl ) ] )
9
- . then ( result => {
10
- console . log ( result )
12
+ router . get ( '/:country' , ( req , res ) => {
13
+ // fetch the data
14
+ get_combined_data ( )
15
+ . then ( response => {
11
16
12
- } )
13
- . catch ( error => console . log ( `Error in promises ${ error } ` ) )
17
+ let countryData = { }
18
+ // loop through all the countries
19
+ response . forEach ( country => {
20
+ // for every country
21
+ // if there is Country/Region is equal to passed country
22
+ if ( country [ 'Country/Region' ] . toString ( ) . toLowerCase ( ) === req . params . country . toLowerCase ( ) ) {
23
+ countryData = country
24
+ }
25
+ } )
26
+ // send the country data back
27
+ res . send ( countryData ) ;
28
+ } ) . catch ( e => console . log ( e ) )
29
+ } ) ;
30
+
31
+ module . exports = router ;
You can’t perform that action at this time.
0 commit comments