Browse Source

Fix import

pull/2923/head
Thomas Kaul 2 years ago
parent
commit
05074d7475
  1. 47
      apps/api/src/app/import/import.service.ts
  2. 13
      apps/api/src/services/data-provider/manual/manual.service.ts

47
apps/api/src/app/import/import.service.ts

@ -575,7 +575,7 @@ export class ImportService {
for (const [ for (const [
index, index,
{ currency, dataSource, symbol } { currency, dataSource, symbol, type }
] of uniqueActivitiesDto.entries()) { ] of uniqueActivitiesDto.entries()) {
if (!this.configurationService.get('DATA_SOURCES').includes(dataSource)) { if (!this.configurationService.get('DATA_SOURCES').includes(dataSource)) {
throw new Error( throw new Error(
@ -583,28 +583,33 @@ export class ImportService {
); );
} }
const assetProfile = ( const assetProfile = {
await this.dataProviderService.getAssetProfiles([ currency,
{ dataSource, symbol } ...(
]) await this.dataProviderService.getAssetProfiles([
)?.[symbol]; { dataSource, symbol }
])
)?.[symbol]
};
if (!assetProfile?.name) { if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') {
throw new Error( if (!assetProfile?.name) {
`activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` throw new Error(
); `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")`
} );
}
if ( if (
assetProfile.currency !== currency && assetProfile.currency !== currency &&
!this.exchangeRateDataService.hasCurrencyPair( !this.exchangeRateDataService.hasCurrencyPair(
currency, currency,
assetProfile.currency assetProfile.currency
) )
) { ) {
throw new Error( throw new Error(
`activities.${index}.currency ("${currency}") does not match with "${assetProfile.currency}" and no exchange rate is available from "${currency}" to "${assetProfile.currency}"` `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 })] = assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })] =

13
apps/api/src/services/data-provider/manual/manual.service.ts

@ -42,10 +42,21 @@ export class ManualService implements DataProviderInterface {
public async getAssetProfile( public async getAssetProfile(
aSymbol: string aSymbol: string
): Promise<Partial<SymbolProfile>> { ): Promise<Partial<SymbolProfile>> {
return { const assetProfile: Partial<SymbolProfile> = {
dataSource: this.getName(), dataSource: this.getName(),
symbol: aSymbol 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) { public async getDividends({}: GetDividendsParams) {

Loading…
Cancel
Save