Browse Source

Improved holdings table showing cash position also when the filter contains accounts

pull/1897/head
francisco 2 years ago
parent
commit
526880de1b
  1. 1
      CHANGELOG.md
  2. 26
      apps/api/src/app/portfolio/portfolio.service.ts

1
CHANGELOG.md

@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed the alignment of the performance column header in the holdings table - Fixed the alignment of the performance column header in the holdings table
- Removed the unnecessary sort header of the comment column in the activities table - Removed the unnecessary sort header of the comment column in the activities table
- Fixed the targets in `proxy.conf.json` from `http://localhost:3333` to `http://0.0.0.0:3333` for local development - Fixed the targets in `proxy.conf.json` from `http://localhost:3333` to `http://0.0.0.0:3333` for local development
- Improved the holdings table by showing the cash position also when the filter contains the accounts, so that we can see the total allocation for that account
## 1.258.0 - 2023-04-20 ## 1.258.0 - 2023-04-20

26
apps/api/src/app/portfolio/portfolio.service.ts

@ -462,10 +462,17 @@ export class PortfolioService {
}); });
const holdings: PortfolioDetails['holdings'] = {}; const holdings: PortfolioDetails['holdings'] = {};
const totalInvestmentInBaseCurrency = currentPositions.totalInvestment.plus( const totalInvestmentInBaseCurrency = currentPositions.currentValue.plus(
cashDetails.balanceInBaseCurrency cashDetails.balanceInBaseCurrency
); );
let filteredValueInBaseCurrency = currentPositions.currentValue;
const isFilteredByAccount = filters.some(
(filter) => filter.type === 'ACCOUNT'
);
let filteredValueInBaseCurrency = isFilteredByAccount
? totalInvestmentInBaseCurrency
: currentPositions.currentValue;
if ( if (
filters?.length === 0 || filters?.length === 0 ||
@ -564,12 +571,11 @@ export class PortfolioService {
}; };
} }
if ( const isFilteredByCash = filters.some(
filters?.length === 0 || (filter) => filter.type === 'ASSET_CLASS' && filter.id === 'CASH'
(filters?.length === 1 && );
filters[0].type === 'ASSET_CLASS' &&
filters[0].id === 'CASH') if (filters.length === 0 || isFilteredByCash || isFilteredByAccount) {
) {
const cashPositions = await this.getCashPositions({ const cashPositions = await this.getCashPositions({
cashDetails, cashDetails,
userCurrency, userCurrency,
@ -595,7 +601,7 @@ export class PortfolioService {
filters[0].id === EMERGENCY_FUND_TAG_ID && filters[0].id === EMERGENCY_FUND_TAG_ID &&
filters[0].type === 'TAG' filters[0].type === 'TAG'
) { ) {
const cashPositions = await this.getCashPositions({ const emergencyFundCashPositions = await this.getCashPositions({
cashDetails, cashDetails,
userCurrency, userCurrency,
value: filteredValueInBaseCurrency value: filteredValueInBaseCurrency
@ -620,7 +626,7 @@ export class PortfolioService {
}; };
holdings[userCurrency] = { holdings[userCurrency] = {
...cashPositions[userCurrency], ...emergencyFundCashPositions[userCurrency],
investment: emergencyFundInCash, investment: emergencyFundInCash,
value: emergencyFundInCash value: emergencyFundInCash
}; };

Loading…
Cancel
Save