From 05074d7475ac088c7b80975fa4dea1f47c065bd7 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:46:32 +0100 Subject: [PATCH] Fix import --- apps/api/src/app/import/import.service.ts | 47 ++++++++++--------- .../data-provider/manual/manual.service.ts | 13 ++++- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts index d564f497b..d2daa4338 100644 --- a/apps/api/src/app/import/import.service.ts +++ b/apps/api/src/app/import/import.service.ts @@ -575,7 +575,7 @@ export class ImportService { for (const [ index, - { currency, dataSource, symbol } + { currency, dataSource, symbol, type } ] of uniqueActivitiesDto.entries()) { if (!this.configurationService.get('DATA_SOURCES').includes(dataSource)) { throw new Error( @@ -583,28 +583,33 @@ export class ImportService { ); } - const assetProfile = ( - await this.dataProviderService.getAssetProfiles([ - { dataSource, symbol } - ]) - )?.[symbol]; + const assetProfile = { + currency, + ...( + 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}")` - ); - } + if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') { + if (!assetProfile?.name) { + throw new Error( + `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` + ); + } - 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.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 })] = diff --git a/apps/api/src/services/data-provider/manual/manual.service.ts b/apps/api/src/services/data-provider/manual/manual.service.ts index f5b285016..74acc48e1 100644 --- a/apps/api/src/services/data-provider/manual/manual.service.ts +++ b/apps/api/src/services/data-provider/manual/manual.service.ts @@ -42,10 +42,21 @@ export class ManualService implements DataProviderInterface { public async getAssetProfile( aSymbol: string ): Promise> { - return { + const assetProfile: Partial = { dataSource: this.getName(), symbol: aSymbol }; + + const [symbolProfile] = await this.symbolProfileService.getSymbolProfiles([ + { dataSource: this.getName(), symbol: aSymbol } + ]); + + if (symbolProfile) { + assetProfile.currency = symbolProfile.currency; + assetProfile.name = symbolProfile.name; + } + + return assetProfile; } public async getDividends({}: GetDividendsParams) {