From bff60ddbe02c5347f26958162f13a5542f572035 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 16 Jan 2024 21:21:51 +0100 Subject: [PATCH] Feature/improve asset profile validation in activities import for manual data source (#2886) * Improve asset profile validation for MANUAL data source * Update changelog --- CHANGELOG.md | 4 ++ apps/api/src/app/import/import.service.ts | 48 +++++++++++------------ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5666ef21..a2a22943a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added the holdings table to the account detail dialog - Validated the currency of the search results in the _EOD Historical Data_ service +### Changed + +- Improved the asset profile validation for `MANUAL` data source in the activities import + ## 2.40.0 - 2024-01-15 ### Changed diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index d15e8d437..d564f497b 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -583,34 +583,32 @@ export class ImportService { ); } - if (dataSource !== 'MANUAL') { - const assetProfile = ( - await this.dataProviderService.getAssetProfiles([ - { dataSource, symbol } - ]) - )?.[symbol]; - - if (!assetProfile?.name) { - throw new Error( - `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` - ); - } + const assetProfile = ( + await this.dataProviderService.getAssetProfiles([ + { dataSource, symbol } + ]) + )?.[symbol]; - if ( - assetProfile.currency !== currency && - !this.exchangeRateDataService.hasCurrencyPair( - currency, - assetProfile.currency - ) - ) { - throw new Error( - `activities.${index}.currency ("${currency}") does not match with "${assetProfile.currency}" and no exchange rate is available from "${currency}" to "${assetProfile.currency}"` - ); - } + if (!assetProfile?.name) { + throw new Error( + `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` + ); + } - assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })] = - assetProfile; + if ( + assetProfile.currency !== currency && + !this.exchangeRateDataService.hasCurrencyPair( + currency, + assetProfile.currency + ) + ) { + throw new Error( + `activities.${index}.currency ("${currency}") does not match with "${assetProfile.currency}" and no exchange rate is available from "${currency}" to "${assetProfile.currency}"` + ); } + + assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })] = + assetProfile; } return assetProfiles;