Browse Source
Bugfix/fix indirect calculation in exchange rate service for specific date (#2026)
* Fix indirect calculation
* Update changelog
pull/2027/head
Thomas Kaul
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
38 additions and
20 deletions
-
CHANGELOG.md
-
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
|
|
@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
|
|
|
|
- Improved the language localization for German (`de`) |
|
|
|
|
|
|
|
### Fixed |
|
|
|
|
|
|
|
- Fixed the exchange rate service for a specific date (indirect calculation via base currency) used in activities with a manual currency |
|
|
|
|
|
|
|
## 1.274.0 - 2023-05-29 |
|
|
|
|
|
|
|
### Added |
|
|
|
|
|
@ -186,28 +186,42 @@ export class ExchangeRateDataService { |
|
|
|
factor = marketData?.marketPrice; |
|
|
|
} else { |
|
|
|
// Calculate indirectly via base currency
|
|
|
|
|
|
|
|
let marketPriceBaseCurrencyFromCurrency: number; |
|
|
|
let marketPriceBaseCurrencyToCurrency: number; |
|
|
|
|
|
|
|
try { |
|
|
|
const [ |
|
|
|
{ marketPrice: marketPriceBaseCurrencyFromCurrency }, |
|
|
|
{ marketPrice: marketPriceBaseCurrencyToCurrency } |
|
|
|
] = await Promise.all([ |
|
|
|
this.marketDataService.get({ |
|
|
|
if (this.baseCurrency === aFromCurrency) { |
|
|
|
marketPriceBaseCurrencyFromCurrency = 1; |
|
|
|
} else { |
|
|
|
marketPriceBaseCurrencyFromCurrency = ( |
|
|
|
await this.marketDataService.get({ |
|
|
|
dataSource, |
|
|
|
date: aDate, |
|
|
|
symbol: `${this.baseCurrency}${aFromCurrency}` |
|
|
|
}), |
|
|
|
this.marketDataService.get({ |
|
|
|
}) |
|
|
|
)?.marketPrice; |
|
|
|
} |
|
|
|
} catch {} |
|
|
|
|
|
|
|
try { |
|
|
|
if (this.baseCurrency === aToCurrency) { |
|
|
|
marketPriceBaseCurrencyToCurrency = 1; |
|
|
|
} else { |
|
|
|
marketPriceBaseCurrencyToCurrency = ( |
|
|
|
await this.marketDataService.get({ |
|
|
|
dataSource, |
|
|
|
date: aDate, |
|
|
|
symbol: `${this.baseCurrency}${aToCurrency}` |
|
|
|
}) |
|
|
|
]); |
|
|
|
)?.marketPrice; |
|
|
|
} |
|
|
|
} catch {} |
|
|
|
|
|
|
|
// Calculate the opposite direction
|
|
|
|
factor = |
|
|
|
(1 / marketPriceBaseCurrencyFromCurrency) * |
|
|
|
marketPriceBaseCurrencyToCurrency; |
|
|
|
} catch {} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|