@@ -7,7 +7,7 @@ const port = process.env.PORT || 3001;
77
88const { getCountryTable, getJSONData, getJSONDataForCountry } = require ( './lib/byCountry' ) ;
99const { getCompleteTable } = require ( './lib/corona' ) ;
10- const { countryUpperCase } = require ( './lib/helpers' ) ;
10+ const { countryUpperCase, lookupCountry } = require ( './lib/helpers' ) ;
1111
1212
1313function errorHandler ( error , res ) {
@@ -34,11 +34,10 @@ app.get('/', (req, res) => {
3434} ) ;
3535
3636app . get ( '/:country' , ( req , res ) => {
37- const { country } = countryUpperCase ( req . params ) ;
38- let lookupObj = null ;
37+ const { country } = req . params ;
3938 const format = req . query . format ? req . query . format : '' ;
4039
41- if ( ! country || country === 'All' ) {
40+ if ( ! country || 'ALL' === country . toUpperCase ( ) ) {
4241 if ( format . toLowerCase ( ) === 'json' ) {
4342 return getJSONData ( ) . then ( result => {
4443 res . setHeader ( 'Cache-Control' , 's-maxage=900' ) ;
@@ -53,13 +52,8 @@ app.get('/:country', (req, res) => {
5352 } ) . catch ( error => errorHandler ( error , res ) ) ;
5453 }
5554
56- try {
57- lookupObj = lookup . byIso ( country )
58- || lookup . byFips ( country )
59- || lookup . byCountry ( country ) ;
60- } catch ( error ) {
61- lookupObj = lookup . byFips ( country ) || lookup . byCountry ( country ) ;
62- }
55+ let lookupObj = lookupCountry ( country ) ;
56+
6357 if ( ! lookupObj ) {
6458 return res . send ( `
6559 Country not found.
@@ -70,6 +64,7 @@ app.get('/:country', (req, res) => {
7064 - /India: for India.
7165 ` ) ;
7266 }
67+
7368 const { iso2 } = lookupObj ;
7469
7570 if ( format . toLowerCase ( ) === 'json' ) {
0 commit comments