Browse Source

Fix X-ray rule exception when marketPrice is null

When a holding has no market price data (e.g. newly added activity
before price data is fetched), Big.js throws "[big.js] Invalid number"
because null is passed to .mul(). This crashes the /api/v1/portfolio/report
endpoint.

Use nullish coalescing (marketPrice ?? 0) to treat missing prices as
zero, consistent with the pattern already used in portfolio.service.ts.

Fixes #4607
pull/6397/head
Abhi 1 month ago
parent
commit
97e730a8a8
  1. 2
      apps/api/src/models/rule.ts

2
apps/api/src/models/rule.ts

@ -57,7 +57,7 @@ export abstract class Rule<T extends RuleSettings> implements RuleInterface<T> {
previousValue +
this.exchangeRateDataService.toCurrency(
new Big(currentValue.quantity)
.mul(currentValue.marketPrice)
.mul(currentValue.marketPrice ?? 0)
.toNumber(),
currentValue.currency,
baseCurrency

Loading…
Cancel
Save