File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -6,15 +6,24 @@ const port = process.env.PORT || 3001;
66const { getCountryTable } = require ( './lib/byCountry' ) ;
77const { getCompleteTable } = require ( './lib/corona' ) ;
88
9+ const countryUpperCase = ( countryParams ) => {
10+ if ( countryParams . country . length > 2 ) {
11+ const country = countryParams . country . toLowerCase ( ) . split ( ' ' ) . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) ) . join ( ' ' ) ;
12+ return { country } ;
13+ }
14+ return countryParams ;
15+ } ;
16+
917app . get ( '/' , ( req , res ) => {
1018 return getCompleteTable ( ) . then ( result => {
1119 return res . send ( result ) ;
1220 } ) . catch ( error => res . send ( error ) ) ;
1321} ) ;
1422
1523app . get ( '/:country' , ( req , res ) => {
16- let { country } = req . params ;
17- if ( ! country || country === 'all' ) {
24+
25+ let { country } = countryUpperCase ( req . params ) ;
26+ if ( ! country || country === 'All' ) {
1827 return getCompleteTable ( ) . then ( result => {
1928 return res . send ( result ) ;
2029 } ) . catch ( error => res . send ( error ) ) ;
You can’t perform that action at this time.
0 commit comments