Browse Source

fix(api): Handle undefined fallback and remove dead code in exchange rates

- Revert  fallback to  in  and  to prevent  crashes downstream.
- Remove dead  dictionary lookups as derived currencies are now normalized correctly at the start of these functions.
- Update `keyv` and `@keyv/redis` to latest versions to fix build errors.
pull/6866/head
Andrea Bugeja 1 week ago
parent
commit
3c9e70ffad
  1. 24
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
  2. 3
      package.json

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

@ -285,7 +285,7 @@ export class ExchangeRateDataService {
'ExchangeRateDataService'
);
return undefined;
return aValue;
}
public async toCurrencyAtDate(
@ -326,16 +326,10 @@ export class ExchangeRateDataService {
);
}
const derivedCurrencyFactor =
this.derivedCurrencyFactors[
`${normalizedFromCurrency}${normalizedToCurrency}`
];
let factor: number;
if (normalizedFromCurrency === normalizedToCurrency) {
factor = 1;
} else if (derivedCurrencyFactor) {
factor = derivedCurrencyFactor;
} else {
const dataSource =
this.dataProviderService.getDataSourceForExchangeRates();
@ -402,7 +396,7 @@ export class ExchangeRateDataService {
'ExchangeRateDataService'
);
return undefined;
return aValue;
}
private async getExchangeRates({
@ -447,20 +441,6 @@ export class ExchangeRateDataService {
return factors;
}
const derivedCurrencyFactor =
this.derivedCurrencyFactors[
`${normalizedCurrencyFrom}${normalizedCurrencyTo}`
];
if (derivedCurrencyFactor) {
for (const date of dates) {
factors[format(date, DATE_FORMAT)] =
conversionFactorFrom * derivedCurrencyFactor * conversionFactorTo;
}
return factors;
}
const dataSource = this.dataProviderService.getDataSourceForExchangeRates();
const symbol = `${normalizedCurrencyFrom}${normalizedCurrencyTo}`;

3
package.json

@ -72,7 +72,7 @@
"@date-fns/utc": "2.1.1",
"@internationalized/number": "3.6.6",
"@ionic/angular": "8.8.5",
"@keyv/redis": "4.4.0",
"@keyv/redis": "^5.1.6",
"@nestjs/bull": "11.0.4",
"@nestjs/cache-manager": "3.1.0",
"@nestjs/common": "11.1.19",
@ -118,6 +118,7 @@
"http-status-codes": "2.3.0",
"ionicons": "8.0.13",
"jsonpath": "1.3.0",
"keyv": "^5.6.0",
"lodash": "4.18.1",
"marked": "17.0.2",
"ms": "3.0.0-canary.1",

Loading…
Cancel
Save