Browse Source

Add missing tags

pull/3243/head
Thomas Kaul 1 year ago
parent
commit
0fcac61e2f
  1. 14
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

14
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -29,7 +29,7 @@ import {
max, max,
subDays subDays
} from 'date-fns'; } from 'date-fns';
import { last, uniq } from 'lodash'; import { last, uniq, uniqBy } from 'lodash';
export abstract class PortfolioCalculator { export abstract class PortfolioCalculator {
protected static readonly ENABLE_LOGGING = false; protected static readonly ENABLE_LOGGING = false;
@ -57,9 +57,10 @@ export abstract class PortfolioCalculator {
this.currentRateService = currentRateService; this.currentRateService = currentRateService;
this.exchangeRateDataService = exchangeRateDataService; this.exchangeRateDataService = exchangeRateDataService;
this.orders = activities.map( this.orders = activities.map(
({ date, fee, quantity, SymbolProfile, type, unitPrice }) => { ({ date, fee, quantity, SymbolProfile, tags = [], type, unitPrice }) => {
return { return {
SymbolProfile, SymbolProfile,
tags,
type, type,
date: format(date, DATE_FORMAT), date: format(date, DATE_FORMAT),
fee: new Big(fee), fee: new Big(fee),
@ -711,17 +712,17 @@ export abstract class PortfolioCalculator {
currentTransactionPointItem = { currentTransactionPointItem = {
investment, investment,
tags,
averagePrice: newQuantity.gt(0) averagePrice: newQuantity.gt(0)
? investment.div(newQuantity) ? investment.div(newQuantity)
: new Big(0), : new Big(0),
currency: SymbolProfile.currency, currency: SymbolProfile.currency,
dataSource: SymbolProfile.dataSource, dataSource: SymbolProfile.dataSource,
dividend: new Big(0), dividend: new Big(0),
fee: fee.plus(oldAccumulatedSymbol.fee), fee: oldAccumulatedSymbol.fee.plus(fee),
firstBuyDate: oldAccumulatedSymbol.firstBuyDate, firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
quantity: newQuantity, quantity: newQuantity,
symbol: SymbolProfile.symbol, symbol: SymbolProfile.symbol,
tags: oldAccumulatedSymbol.tags.concat(tags),
transactionCount: oldAccumulatedSymbol.transactionCount + 1 transactionCount: oldAccumulatedSymbol.transactionCount + 1
}; };
} else { } else {
@ -740,6 +741,11 @@ export abstract class PortfolioCalculator {
}; };
} }
currentTransactionPointItem.tags = uniqBy(
currentTransactionPointItem.tags,
'id'
);
symbols[SymbolProfile.symbol] = currentTransactionPointItem; symbols[SymbolProfile.symbol] = currentTransactionPointItem;
const items = lastTransactionPoint?.items ?? []; const items = lastTransactionPoint?.items ?? [];

Loading…
Cancel
Save