Browse Source

Refactoring

pull/3267/head
Thomas Kaul 1 year ago
parent
commit
ec25207a42
  1. 41
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -375,7 +375,8 @@ export class PortfolioService {
currency: userCurrency currency: userCurrency
}); });
const currentPositions = await portfolioCalculator.getSnapshot(); const { currentValueInBaseCurrency, hasErrors, positions } =
await portfolioCalculator.getSnapshot();
const cashDetails = await this.accountService.getCashDetails({ const cashDetails = await this.accountService.getCashDetails({
filters, filters,
@ -385,8 +386,7 @@ export class PortfolioService {
const holdings: PortfolioDetails['holdings'] = {}; const holdings: PortfolioDetails['holdings'] = {};
const totalValueInBaseCurrency = const totalValueInBaseCurrency = currentValueInBaseCurrency.plus(
currentPositions.currentValueInBaseCurrency.plus(
cashDetails.balanceInBaseCurrency cashDetails.balanceInBaseCurrency
); );
@ -406,7 +406,7 @@ export class PortfolioService {
let filteredValueInBaseCurrency = isFilteredByAccount let filteredValueInBaseCurrency = isFilteredByAccount
? totalValueInBaseCurrency ? totalValueInBaseCurrency
: currentPositions.currentValueInBaseCurrency; : currentValueInBaseCurrency;
if ( if (
filters?.length === 0 || filters?.length === 0 ||
@ -419,14 +419,12 @@ export class PortfolioService {
); );
} }
const dataGatheringItems = currentPositions.positions.map( const dataGatheringItems = positions.map(({ dataSource, symbol }) => {
({ dataSource, symbol }) => {
return { return {
dataSource, dataSource,
symbol symbol
}; };
} });
);
const [dataProviderResponses, symbolProfiles] = await Promise.all([ const [dataProviderResponses, symbolProfiles] = await Promise.all([
this.dataProviderService.getQuotes({ user, items: dataGatheringItems }), this.dataProviderService.getQuotes({ user, items: dataGatheringItems }),
@ -439,7 +437,7 @@ export class PortfolioService {
} }
const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {}; const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {};
for (const position of currentPositions.positions) { for (const position of positions) {
portfolioItemsNow[position.symbol] = position; portfolioItemsNow[position.symbol] = position;
} }
@ -462,7 +460,7 @@ export class PortfolioService {
tags, tags,
transactionCount, transactionCount,
valueInBaseCurrency valueInBaseCurrency
} of currentPositions.positions) { } of positions) {
if (isFilteredByClosedHoldings === true) { if (isFilteredByClosedHoldings === true) {
if (!quantity.eq(0)) { if (!quantity.eq(0)) {
// Ignore positions with a quantity // Ignore positions with a quantity
@ -603,10 +601,10 @@ export class PortfolioService {
return { return {
accounts, accounts,
hasErrors,
holdings, holdings,
platforms, platforms,
summary, summary
hasErrors: currentPositions.hasErrors
}; };
} }
@ -679,9 +677,9 @@ export class PortfolioService {
const portfolioStart = portfolioCalculator.getStartDate(); const portfolioStart = portfolioCalculator.getStartDate();
const transactionPoints = portfolioCalculator.getTransactionPoints(); const transactionPoints = portfolioCalculator.getTransactionPoints();
const currentPositions = await portfolioCalculator.getSnapshot(); const { positions } = await portfolioCalculator.getSnapshot();
const position = currentPositions.positions.find(({ symbol }) => { const position = positions.find(({ symbol }) => {
return symbol === aSymbol; return symbol === aSymbol;
}); });
@ -937,9 +935,9 @@ export class PortfolioService {
currency: this.request.user.Settings.settings.baseCurrency currency: this.request.user.Settings.settings.baseCurrency
}); });
const currentPositions = await portfolioCalculator.getSnapshot(); let { hasErrors, positions } = await portfolioCalculator.getSnapshot();
let positions = currentPositions.positions.filter(({ quantity }) => { positions = positions.filter(({ quantity }) => {
return !quantity.eq(0); return !quantity.eq(0);
}); });
@ -978,7 +976,7 @@ export class PortfolioService {
} }
return { return {
hasErrors: currentPositions.hasErrors, hasErrors,
positions: positions.map( positions: positions.map(
({ ({
averagePrice, averagePrice,
@ -1239,11 +1237,10 @@ export class PortfolioService {
currency: this.request.user.Settings.settings.baseCurrency currency: this.request.user.Settings.settings.baseCurrency
}); });
const currentPositions = await portfolioCalculator.getSnapshot(); let { positions, totalInvestment } =
await portfolioCalculator.getSnapshot();
const positions = currentPositions.positions.filter( positions = positions.filter((item) => !item.quantity.eq(0));
(item) => !item.quantity.eq(0)
);
const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {}; const portfolioItemsNow: { [symbol: string]: TimelinePosition } = {};
@ -1305,7 +1302,7 @@ export class PortfolioService {
[ [
new FeeRatioInitialInvestment( new FeeRatioInitialInvestment(
this.exchangeRateDataService, this.exchangeRateDataService,
currentPositions.totalInvestment.toNumber(), totalInvestment.toNumber(),
this.getFees({ activities, userCurrency }).toNumber() this.getFees({ activities, userCurrency }).toNumber()
) )
], ],

Loading…
Cancel
Save