Browse Source

Modified chart item

pull/2569/head
Manushreshta B L 2 years ago
parent
commit
9c3458f4e9
  1. 11
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 16
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 2
      apps/api/src/services/account-balance/account-balance.service.ts
  4. 2
      libs/common/src/lib/interfaces/historical-data-item.interface.ts

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

@ -346,10 +346,19 @@ export class PortfolioController {
this.userService.isRestrictedView(this.request.user)
) {
performanceInformation.chart = performanceInformation.chart.map(
({ date, netPerformanceInPercentage, totalInvestment, value }) => {
({
date,
netPerformanceInPercentage,
totalInvestment,
value,
totalAccountBalance,
netWorth
}) => {
return {
date,
netPerformanceInPercentage,
netWorth,
totalAccountBalance,
totalInvestment: new Big(totalInvestment)
.div(performanceInformation.performance.totalInvestment)
.toNumber(),

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

@ -1,3 +1,4 @@
import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service';
import { AccountService } from '@ghostfolio/api/app/account/account.service';
import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface';
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
@ -91,6 +92,7 @@ const europeMarkets = require('../../assets/countries/europe-markets.json');
@Injectable()
export class PortfolioService {
public constructor(
private readonly accountBalanceService: AccountBalanceService,
private readonly accountService: AccountService,
private readonly currentRateService: CurrentRateService,
private readonly dataProviderService: DataProviderService,
@ -1195,6 +1197,16 @@ export class PortfolioService {
).div(100);
}
const balancesValue = await this.accountBalanceService.getAccountBalances({
userId: userId
});
let totalBalance = 0;
balancesValue.balances.map((item) => {
totalBalance += item.value;
});
return {
errors,
hasErrors,
@ -1211,7 +1223,9 @@ export class PortfolioService {
netPerformanceInPercentage,
value,
netPerformance: netPerformanceOfItem,
totalInvestment: totalInvestmentOfItem
totalInvestment: totalInvestmentOfItem,
totalAccountBalance: totalBalance,
netWorth: value + totalBalance
};
}
),

2
apps/api/src/services/account-balance/account-balance.service.ts

@ -19,7 +19,7 @@ export class AccountBalanceService {
accountId,
userId
}: {
accountId: string;
accountId?: string;
userId: string;
}): Promise<AccountBalancesResponse> {
const balances = await this.prismaService.accountBalance.findMany({

2
libs/common/src/lib/interfaces/historical-data-item.interface.ts

@ -5,7 +5,9 @@ export interface HistoricalDataItem {
marketPrice?: number;
netPerformance?: number;
netPerformanceInPercentage?: number;
netWorth?: number;
quantity?: number;
totalAccountBalance?: number;
totalInvestment?: number;
value?: number;
valueInPercentage?: number;

Loading…
Cancel
Save