diff --git a/CHANGELOG.md b/CHANGELOG.md index 684b9d64..b60940bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed an issue with the detection of the thousand separator by locale +- Fixed an issue with holdings and sectors while using symbol profile overrides - Fixed an issue with the MIME type detection in the scraper configuration ## 2.135.0 - 2025-01-19 diff --git a/apps/api/src/services/symbol-profile/symbol-profile.service.ts b/apps/api/src/services/symbol-profile/symbol-profile.service.ts index eb8778c3..df0526d9 100644 --- a/apps/api/src/services/symbol-profile/symbol-profile.service.ts +++ b/apps/api/src/services/symbol-profile/symbol-profile.service.ts @@ -177,9 +177,13 @@ export class SymbolProfileService { symbolProfile?.countries as unknown as Prisma.JsonArray ), dateOfFirstActivity: undefined as Date, - holdings: this.getHoldings(symbolProfile), + holdings: this.getHoldings( + symbolProfile?.holdings as unknown as Prisma.JsonArray + ), scraperConfiguration: this.getScraperConfiguration(symbolProfile), - sectors: this.getSectors(symbolProfile), + sectors: this.getSectors( + symbolProfile?.sectors as unknown as Prisma.JsonArray + ), symbolMapping: this.getSymbolMapping(symbolProfile) }; @@ -209,8 +213,9 @@ export class SymbolProfileService { (item.SymbolProfileOverrides.holdings as unknown as Holding[]) ?.length > 0 ) { - item.holdings = item.SymbolProfileOverrides - .holdings as unknown as Holding[]; + item.holdings = this.getHoldings( + item.SymbolProfileOverrides?.holdings as unknown as Prisma.JsonArray + ); } item.name = item.SymbolProfileOverrides?.name ?? item.name; @@ -219,8 +224,9 @@ export class SymbolProfileService { (item.SymbolProfileOverrides.sectors as unknown as Sector[])?.length > 0 ) { - item.sectors = item.SymbolProfileOverrides - .sectors as unknown as Sector[]; + item.sectors = this.getSectors( + item.SymbolProfileOverrides?.sectors as unknown as Prisma.JsonArray + ); } item.url = item.SymbolProfileOverrides?.url ?? item.url; @@ -249,18 +255,20 @@ export class SymbolProfileService { }); } - private getHoldings(symbolProfile: SymbolProfile): Holding[] { - return ((symbolProfile?.holdings as Prisma.JsonArray) ?? []).map( - (holding) => { - const { name, weight } = holding as Prisma.JsonObject; + private getHoldings(aHoldings: Prisma.JsonArray = []): Holding[] { + if (aHoldings === null) { + return []; + } - return { - allocationInPercentage: weight as number, - name: (name as string) ?? UNKNOWN_KEY, - valueInBaseCurrency: undefined - }; - } - ); + return aHoldings.map((holding) => { + const { name, weight } = holding as Prisma.JsonObject; + + return { + allocationInPercentage: weight as number, + name: (name as string) ?? UNKNOWN_KEY, + valueInBaseCurrency: undefined + }; + }); } private getScraperConfiguration( @@ -285,17 +293,19 @@ export class SymbolProfileService { return null; } - private getSectors(symbolProfile: SymbolProfile): Sector[] { - return ((symbolProfile?.sectors as Prisma.JsonArray) ?? []).map( - (sector) => { - const { name, weight } = sector as Prisma.JsonObject; + private getSectors(aSectors: Prisma.JsonArray = []): Sector[] { + if (aSectors === null) { + return []; + } - return { - name: (name as string) ?? UNKNOWN_KEY, - weight: weight as number - }; - } - ); + return aSectors.map((sector) => { + const { name, weight } = sector as Prisma.JsonObject; + + return { + name: (name as string) ?? UNKNOWN_KEY, + weight: weight as number + }; + }); } private getSymbolMapping(symbolProfile: SymbolProfile) { diff --git a/libs/common/src/lib/interfaces/holding.interface.ts b/libs/common/src/lib/interfaces/holding.interface.ts index 5a0df62f..e963bc5a 100644 --- a/libs/common/src/lib/interfaces/holding.interface.ts +++ b/libs/common/src/lib/interfaces/holding.interface.ts @@ -1,5 +1,5 @@ export interface Holding { - allocationInPercentage?: number; + allocationInPercentage: number; name: string; valueInBaseCurrency: number; }