Browse Source

Refactoring

pull/3118/head
Thomas Kaul 1 year ago
parent
commit
93f49bfe10
  1. 11
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

11
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

@ -73,14 +73,17 @@ export class ExchangeRateDataService {
currencyTo: targetCurrency currencyTo: targetCurrency
}); });
const keys = Object.keys( const dateStrings = Object.keys(
exchangeRatesByCurrency[`${currency}${targetCurrency}`] exchangeRatesByCurrency[`${currency}${targetCurrency}`]
); );
const lastDate = keys.reduce((a, b) => (a > b ? a : b)); const lastDateString = dateStrings.reduce((a, b) => {
return a > b ? a : b;
});
let previousExchangeRate = let previousExchangeRate =
exchangeRatesByCurrency[`${currency}${targetCurrency}`]?.[lastDate] ?? exchangeRatesByCurrency[`${currency}${targetCurrency}`]?.[
1; lastDateString
] ?? 1;
// Start from the most recent date and fill in missing exchange rates // Start from the most recent date and fill in missing exchange rates
// using the latest available rate // using the latest available rate

Loading…
Cancel
Save