From f48832c671c6b72aad596b910e15dc11193a1138 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 23 May 2022 18:04:09 +0200 Subject: [PATCH] Bugfix/add missing conversion of countries (#941) * Add missing conversion of countries for SymbolProfileOverrides * Update changelog --- CHANGELOG.md | 6 +++ .../src/services/symbol-profile.service.ts | 46 ++++++++++++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0b90eda1..5d195d5ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fixed an issue with the missing conversion of countries in the symbol profile overrides + ## 1.150.0 - 21.05.2022 ### Changed diff --git a/apps/api/src/services/symbol-profile.service.ts b/apps/api/src/services/symbol-profile.service.ts index 5c8839ebf..d7a0c4cfd 100644 --- a/apps/api/src/services/symbol-profile.service.ts +++ b/apps/api/src/services/symbol-profile.service.ts @@ -59,7 +59,9 @@ export class SymbolProfileService { return symbolProfiles.map((symbolProfile) => { const item = { ...symbolProfile, - countries: this.getCountries(symbolProfile), + countries: this.getCountries( + symbolProfile?.countries as unknown as Prisma.JsonArray + ), scraperConfiguration: this.getScraperConfiguration(symbolProfile), sectors: this.getSectors(symbolProfile), symbolMapping: this.getSymbolMapping(symbolProfile) @@ -70,9 +72,17 @@ export class SymbolProfileService { item.SymbolProfileOverrides.assetClass ?? item.assetClass; item.assetSubClass = item.SymbolProfileOverrides.assetSubClass ?? item.assetSubClass; - item.countries = - (item.SymbolProfileOverrides.countries as unknown as Country[]) ?? - item.countries; + + if ( + (item.SymbolProfileOverrides.countries as unknown as Prisma.JsonArray) + ?.length > 0 + ) { + item.countries = this.getCountries( + item.SymbolProfileOverrides + ?.countries as unknown as Prisma.JsonArray + ); + } + item.name = item.SymbolProfileOverrides?.name ?? item.name; item.sectors = (item.SymbolProfileOverrides.sectors as unknown as Sector[]) ?? @@ -85,20 +95,22 @@ export class SymbolProfileService { }); } - private getCountries(symbolProfile: SymbolProfile): Country[] { - return ((symbolProfile?.countries as Prisma.JsonArray) ?? []).map( - (country) => { - const { code, weight } = country as Prisma.JsonObject; + private getCountries(aCountries: Prisma.JsonArray = []): Country[] { + if (aCountries === null) { + return []; + } - return { - code: code as string, - continent: - continents[countries[code as string]?.continent] ?? UNKNOWN_KEY, - name: countries[code as string]?.name ?? UNKNOWN_KEY, - weight: weight as number - }; - } - ); + return aCountries.map((country: Pick) => { + const { code, weight } = country; + + return { + code, + weight, + continent: + continents[countries[code as string]?.continent] ?? UNKNOWN_KEY, + name: countries[code as string]?.name ?? UNKNOWN_KEY + }; + }); } private getScraperConfiguration(