From 2da15d43e7b2a901f9abe19a5a4e86346eddd7be Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 8 Aug 2026 10:27:48 +0200 Subject: [PATCH] Handle unknown country names --- apps/api/src/helper/country.helper.ts | 7 +++++++ .../trackinsight/trackinsight.service.ts | 14 ++++++++------ .../financial-modeling-prep.service.ts | 6 +++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/api/src/helper/country.helper.ts b/apps/api/src/helper/country.helper.ts index 1d9f8f99a..ecb28b8d3 100644 --- a/apps/api/src/helper/country.helper.ts +++ b/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; } diff --git a/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts b/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts index 29e4e5129..7f58448b7 100644 --- a/apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts +++ b/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( 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 }); + } } } diff --git a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts index f7f2e7eb9..f4c36d256 100644 --- a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts +++ b/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