Skip to content

Commit 584479f

Browse files
authored
Merge pull request sagarkarira#9 from mtiifa/master
fixing the lowercase country name issue
2 parents c34e15f + dd945bc commit 584479f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const port = process.env.PORT || 3001;
77

88
const { getCountryTable, getJSONData, getJSONDataForCountry } = require('./lib/byCountry');
99
const { getCompleteTable } = require('./lib/corona');
10+
const { countryUpperCase } = require('./lib/helpers');
11+
1012

1113
function errorHandler(error, res) {
1214
console.error(error);
@@ -32,18 +34,20 @@ app.get('/', (req, res) => {
3234
});
3335

3436
app.get('/:country', (req, res) => {
35-
const { country } = req.params;
37+
38+
const { country } = countryUpperCase(req.params);
3639
let lookupObj = null;
3740
const format = req.query.format ? req.query.format : '';
3841

39-
if (!country || country === 'all') {
42+
if (!country || country === 'All') {
4043
if (format.toLowerCase() === 'json') {
4144
return getJSONData().then(result => {
4245
res.setHeader('Cache-Control', 's-maxage=900');
4346
return res.json(result);
4447
}).catch(error => errorHandler(error, res));
4548
}
4649

50+
4751
return getCompleteTable().then(result => {
4852
res.setHeader('Cache-Control', 's-maxage=900');
4953
return res.send(result);

lib/helpers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ e.getTotalStats = (countryData) => {
145145
return worldStats;
146146
};
147147

148+
e.countryUpperCase = (countryParams) => {
149+
if(countryParams.country.length > 2 ){
150+
const country = countryParams.country.toLowerCase().split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
151+
return { country };
152+
}
153+
return countryParams;
154+
};
155+
148156
e.footer = `
149157
150158
Stay safe. Stay inside.

0 commit comments

Comments
 (0)