Browse Source

Handle unknown country names

pull/7574/head
Thomas Kaul 3 weeks ago
parent
commit
2da15d43e7
  1. 7
      apps/api/src/helper/country.helper.ts
  2. 14
      apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts
  3. 6
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

7
apps/api/src/helper/country.helper.ts

@ -1,3 +1,4 @@
import { Logger } from '@nestjs/common';
import { countries } from 'countries-list';
export function getCountryCodeByName({
@ -17,5 +18,11 @@ export function getCountryCodeByName({
}
}
if (name) {
const logger = new Logger('getCountryCodeByName');
logger.warn(`Could not map the country "${name}" to a code`);
}
return undefined;
}

14
apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts

@ -16,6 +16,7 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
private static baseUrl = 'https://www.trackinsight.com';
private static countriesMapping = {
'Czech Republic': 'CZ',
'Republic of Korea': 'KR',
'Russian Federation': 'RU',
Turkey: 'TR',
@ -125,13 +126,14 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
for (const [name, value] of Object.entries<any>(
holdings?.countries ?? {}
)) {
response.countries.push({
code: getCountryCodeByName({
name,
aliases: TrackinsightDataEnhancerService.countriesMapping
}),
weight: value.weight
const code = getCountryCodeByName({
name,
aliases: TrackinsightDataEnhancerService.countriesMapping
});
if (code) {
response.countries.push({ code, weight: value.weight });
}
}
}

6
apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

@ -169,9 +169,6 @@ export class FinancialModelingPrepService
.then((res) => res.json());
response.countries = etfCountryWeightings
.filter(({ country: countryName }) => {
return countryName.toLowerCase() !== 'other';
})
.map(({ country: countryName, weightPercentage }) => {
return {
code: getCountryCodeByName({
@ -180,6 +177,9 @@ export class FinancialModelingPrepService
}),
weight: parseFloat(`${weightPercentage}`) / 100
};
})
.filter(({ code }) => {
return !!code;
});
const etfHoldings = await this.fetchService

Loading…
Cancel
Save