Skip to content

Commit

Permalink
Incorporate names from the geocoding service into the list of responses
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Mar 14, 2022
1 parent c5e1332 commit f4d10b2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions verification/curator-service/api/src/controllers/geocode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';

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

Expand Down Expand Up @@ -62,9 +62,24 @@ export default class GeocodeProxy {
const namesMap: {
[key: string]: string[] | undefined
} = {};
allCodes.forEach((code) => {
namesMap[code] = countries.getName(code, 'en', { select: 'all' });
});
for (const code of allCodes) {
const names = countries.getName(code, 'en', { select: 'all' });
// ask the geocoding service what name it uses
try {
const res = await axios.get<string, AxiosResponse<string>>(
this.locationServiceURL + `/geocode/countryName?c=${code}`
)
const geocodeName = res.data;
if (names.indexOf(geocodeName) < 0) {
names.push(geocodeName);
}
}
catch (err) {
// doesn't matter, weird that geocoding service doesn't have this code though
logger.warn(`geocoding service doesn't have a name for country code ${code} found in the DB!`);
}
namesMap[code] = names;
}
res.status(200).json(namesMap);
}

Expand Down

0 comments on commit f4d10b2

Please sign in to comment.