Skip to content

Commit 7e8b511

Browse files
authored
Merge pull request sagarkarira#111 from burhan/multi-country-filter
adding a country filter
2 parents da5b1f3 + b46a346 commit 7e8b511

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ app.get('/:country', (req, res) => {
157157
const emojis = req.query.emojis === 'true';
158158
const source = req.query.source ? Number(req.query.source) : 2;
159159

160-
if (!country || country.toUpperCase() === 'ALL') {
160+
if (!country || country.toUpperCase() === 'ALL' || country.includes(',')) {
161161
if (format.toLowerCase() === 'json') {
162-
return getWorldoMetersTable({ isCurl, emojis, minimal, format }).then(result => {
162+
return getWorldoMetersTable({ countryCode: country, isCurl, emojis, minimal, format }).then(result => {
163163
return res.json(result);
164164
}).catch(error => errorHandler(error, req, res));
165165
}
166166

167-
return getWorldoMetersTable({ isCurl, emojis, minimal })
167+
return getWorldoMetersTable({ countryCode: country, isCurl, emojis, minimal })
168168
.then(result => {
169169
return res.send(result);
170170
}).catch(error => errorHandler(error, req, res));

lib/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ exports.getWorldoMetersData = async (countryCode = 'ALL') => {
8888
worldStats.confirmed = worldStats.cases;
8989
let finalData = result.data;
9090
if (countryCode && countryCode !== 'ALL') {
91-
finalData = finalData.filter((obj) => obj.countryCode === countryCode);
91+
// extra filter to cater for trailing comma, ie /gb,
92+
finalData = finalData.filter((obj) => countryCode.toLowerCase().split(',').filter((obj) => obj.length > 1).includes(obj.countryCode.toLowerCase()));
9293
}
9394
const returnObj = { data: finalData, worldStats };
9495

0 commit comments

Comments
 (0)