Skip to content

Commit

Permalink
#2559 return map of code to country names
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Mar 14, 2022
1 parent c9d8688 commit 4e66dc4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
30 changes: 30 additions & 0 deletions verification/curator-service/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions verification/curator-service/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"express": "^4.17.1",
"express-openapi-validator": "^4.9.0",
"express-session": "^1.17.1",
"i18n-iso-countries": "^7.3.0",
"iso-3166-1": "^2.1.1",
"jsonwebtoken": "^8.5.1",
"jszip": "^3.7.0",
Expand Down
11 changes: 9 additions & 2 deletions verification/curator-service/api/src/controllers/geocode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Request, Response } from 'express';

import axios, { AxiosError } from 'axios';
import countries from 'i18n-iso-countries';
import mongoose from 'mongoose';

import { logger } from '../util/logger';
Expand Down Expand Up @@ -57,8 +58,14 @@ export default class GeocodeProxy {
const mongoClient = mongoose.connection.getClient();
const locationCountryCodes = await mongoClient.db().collection('cases').distinct('location.country');
const travelHistoryCodes = await mongoClient.db().collection('cases').distinct('travelHistory.travel.location.country');
const allCodes = Array.from(new Set(locationCountryCodes.concat(travelHistoryCodes)).values());
res.status(200).json({'codes': allCodes});
const allCodes = new Set<string>(locationCountryCodes.concat(travelHistoryCodes));
const namesMap: {
[key: string]: string[] | undefined
} = {};
allCodes.forEach((code) => {
namesMap[code] = countries.getName(code, 'en', { select: 'all' });
});
res.status(200).json(namesMap);
}

seed = async (req: Request, res: Response): Promise<void> => {
Expand Down

0 comments on commit 4e66dc4

Please sign in to comment.