Bugfix/improve asset profile validation in activities import (#3057)
* Improve asset profile validation * Update changelog
This commit is contained in:
parent
2bc8bebfb8
commit
f2d431a6b8
@ -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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Improved the asset profile validation in the activities import
|
||||||
|
|
||||||
## 2.57.0 - 2024-02-25
|
## 2.57.0 - 2024-02-25
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -570,17 +570,10 @@ export class ImportService {
|
|||||||
[assetProfileIdentifier: string]: Partial<SymbolProfile>;
|
[assetProfileIdentifier: string]: Partial<SymbolProfile>;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
const uniqueActivitiesDto = uniqBy(
|
|
||||||
activitiesDto,
|
|
||||||
({ dataSource, symbol }) => {
|
|
||||||
return getAssetProfileIdentifier({ dataSource, symbol });
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const [
|
for (const [
|
||||||
index,
|
index,
|
||||||
{ currency, dataSource, symbol, type }
|
{ currency, dataSource, symbol, type }
|
||||||
] of uniqueActivitiesDto.entries()) {
|
] of activitiesDto.entries()) {
|
||||||
if (!this.configurationService.get('DATA_SOURCES').includes(dataSource)) {
|
if (!this.configurationService.get('DATA_SOURCES').includes(dataSource)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`activities.${index}.dataSource ("${dataSource}") is not valid`
|
`activities.${index}.dataSource ("${dataSource}") is not valid`
|
||||||
@ -602,37 +595,33 @@ export class ImportService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetProfile = {
|
if (!assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })]) {
|
||||||
currency,
|
const assetProfile = {
|
||||||
...(
|
currency,
|
||||||
await this.dataProviderService.getAssetProfiles([
|
...(
|
||||||
{ dataSource, symbol }
|
await this.dataProviderService.getAssetProfiles([
|
||||||
])
|
{ dataSource, symbol }
|
||||||
)?.[symbol]
|
])
|
||||||
};
|
)?.[symbol]
|
||||||
|
};
|
||||||
|
|
||||||
if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') {
|
if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') {
|
||||||
if (!assetProfile?.name) {
|
if (!assetProfile?.name) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")`
|
`activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assetProfile.currency !== currency) {
|
||||||
|
throw new Error(
|
||||||
|
`activities.${index}.currency ("${currency}") does not match with currency of ${assetProfile.symbol} ("${assetProfile.currency}")`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })] =
|
||||||
assetProfile.currency !== currency &&
|
assetProfile;
|
||||||
!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;
|
return assetProfiles;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user