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) this.userService.isRestrictedView(this.request.user)
) { ) {
performanceInformation.chart = performanceInformation.chart.map( performanceInformation.chart = performanceInformation.chart.map(
({ date, netPerformanceInPercentage, totalInvestment, value }) => { ({
date,
netPerformanceInPercentage,
totalInvestment,
value,
totalAccountBalance,
netWorth
}) => {
return { return {
date, date,
netPerformanceInPercentage, netPerformanceInPercentage,
netWorth,
totalAccountBalance,
totalInvestment: new Big(totalInvestment) totalInvestment: new Big(totalInvestment)
.div(performanceInformation.performance.totalInvestment) .div(performanceInformation.performance.totalInvestment)
.toNumber(), .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 { AccountService } from '@ghostfolio/api/app/account/account.service';
import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface'; import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface';
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
@ -91,6 +92,7 @@ const europeMarkets = require('../../assets/countries/europe-markets.json');
@Injectable() @Injectable()
export class PortfolioService { export class PortfolioService {
public constructor( public constructor(
private readonly accountBalanceService: AccountBalanceService,
private readonly accountService: AccountService, private readonly accountService: AccountService,
private readonly currentRateService: CurrentRateService, private readonly currentRateService: CurrentRateService,
private readonly dataProviderService: DataProviderService, private readonly dataProviderService: DataProviderService,
@ -1195,6 +1197,16 @@ export class PortfolioService {
).div(100); ).div(100);
} }
const balancesValue = await this.accountBalanceService.getAccountBalances({
userId: userId
});
let totalBalance = 0;
balancesValue.balances.map((item) => {
totalBalance += item.value;
});
return { return {
errors, errors,
hasErrors, hasErrors,
@ -1211,7 +1223,9 @@ export class PortfolioService {
netPerformanceInPercentage, netPerformanceInPercentage,
value, value,
netPerformance: netPerformanceOfItem, 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, accountId,
userId userId
}: { }: {
accountId: string; accountId?: string;
userId: string; userId: string;
}): Promise<AccountBalancesResponse> { }): Promise<AccountBalancesResponse> {
const balances = await this.prismaService.accountBalance.findMany({ 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; marketPrice?: number;
netPerformance?: number; netPerformance?: number;
netPerformanceInPercentage?: number; netPerformanceInPercentage?: number;
netWorth?: number;
quantity?: number; quantity?: number;
totalAccountBalance?: number;
totalInvestment?: number; totalInvestment?: number;
value?: number; value?: number;
valueInPercentage?: number; valueInPercentage?: number;

Loading…
Cancel
Save