Skip to content

Commit c62a0e4

Browse files
committed
fixing the lowercase country name parameter issue
1 parent 6ad516c commit c62a0e4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ const port = process.env.PORT || 3001;
66
const { getCountryTable } = require('./lib/byCountry');
77
const { 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+
917
app.get('/', (req, res) => {
1018
return getCompleteTable().then(result => {
1119
return res.send(result);
1220
}).catch(error => res.send(error));
1321
});
1422

1523
app.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));

0 commit comments

Comments
 (0)