Browse Source

Merge 7baa6ed497 into f6b25eec05

pull/7883/merge
lorenzozane 2 days ago
committed by GitHub
parent
commit
99ad05bfae
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 19
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 1
      libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts

4
apps/api/src/app/portfolio/portfolio.controller.ts

@ -400,13 +400,11 @@ export class PortfolioController {
filterByTags: tags
});
const holdings = await this.portfolioService.getHoldings({
return this.portfolioService.getHoldings({
filters,
userId,
dateRange: range
});
return { holdings };
}
@Get('investments')

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

@ -59,6 +59,7 @@ import {
InvestmentItem,
PortfolioDetails,
PortfolioHoldingResponse,
PortfolioHoldingsResponse,
PortfolioInvestmentsResponse,
PortfolioPerformanceResponse,
PortfolioPosition,
@ -508,7 +509,14 @@ export class PortfolioService {
});
}
return holdings;
return {
holdings,
totalValueInBaseCurrency: getSum(
holdings.map(({ valueInBaseCurrency }) => {
return new Big(valueInBaseCurrency ?? 0);
})
).toNumber()
};
}
public async getInvestments({
@ -1241,7 +1249,7 @@ export class PortfolioService {
subscriptionType: user.subscription?.type
});
const { errors, hasErrors, historicalData } =
const { currentValueInBaseCurrency, errors, hasErrors, historicalData } =
await portfolioCalculator.getSnapshot();
const { endDate, startDate } = getIntervalFromDateRange({ dateRange });
@ -1258,8 +1266,7 @@ export class PortfolioService {
netPerformanceWithCurrencyEffect,
netWorth,
totalInvestment,
totalInvestmentValueWithCurrencyEffect,
valueWithCurrencyEffect
totalInvestmentValueWithCurrencyEffect
} = chart?.at(-1) ?? {
netPerformance: 0,
netPerformanceInPercentage: 0,
@ -1267,7 +1274,7 @@ export class PortfolioService {
netPerformanceWithCurrencyEffect: 0,
netWorth: 0,
totalInvestment: 0,
valueWithCurrencyEffect: 0
totalInvestmentValueWithCurrencyEffect: 0
};
return {
@ -1281,7 +1288,7 @@ export class PortfolioService {
totalInvestment,
totalInvestmentValueWithCurrencyEffect,
currentNetWorth: netWorth,
currentValueInBaseCurrency: valueWithCurrencyEffect,
currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(),
netPerformancePercentage: netPerformanceInPercentage,
netPerformancePercentageWithCurrencyEffect:
netPerformanceInPercentageWithCurrencyEffect

1
libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts

@ -2,4 +2,5 @@ import { PortfolioPosition } from '@ghostfolio/common/interfaces';
export interface PortfolioHoldingsResponse {
holdings: PortfolioPosition[];
totalValueInBaseCurrency: number;
}

Loading…
Cancel
Save