Browse Source

Eliminate name from timeline position

Get the name from the symbolProfileService instead
pull/245/head
Thomas 4 years ago
parent
commit
284aad9cd6
  1. 1
      apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts
  2. 7
      apps/api/src/app/core/portfolio-calculator.ts
  3. 5
      apps/api/src/app/order/order.controller.ts
  4. 17
      apps/api/src/app/portfolio/portfolio.service.ts
  5. 7
      apps/client/src/app/components/transactions-table/transactions-table.component.html
  6. 1
      libs/common/src/lib/interfaces/timeline-position.interface.ts

1
apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts

@ -5,7 +5,6 @@ export interface TransactionPointSymbol {
currency: Currency; currency: Currency;
firstBuyDate: string; firstBuyDate: string;
investment: Big; investment: Big;
name: string;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
transactionCount: number; transactionCount: number;

7
apps/api/src/app/core/portfolio-calculator.ts

@ -23,8 +23,7 @@ import {
isAfter, isAfter,
isBefore, isBefore,
max, max,
min, min
subDays
} from 'date-fns'; } from 'date-fns';
import { flatten } from 'lodash'; import { flatten } from 'lodash';
@ -60,7 +59,6 @@ export class PortfolioCalculator {
.mul(order.quantity) .mul(order.quantity)
.mul(factor) .mul(factor)
.add(oldAccumulatedSymbol.investment), .add(oldAccumulatedSymbol.investment),
name: order.name,
quantity: order.quantity quantity: order.quantity
.mul(factor) .mul(factor)
.plus(oldAccumulatedSymbol.quantity), .plus(oldAccumulatedSymbol.quantity),
@ -72,7 +70,6 @@ export class PortfolioCalculator {
currency: order.currency, currency: order.currency,
firstBuyDate: order.date, firstBuyDate: order.date,
investment: unitPrice.mul(order.quantity).mul(factor), investment: unitPrice.mul(order.quantity).mul(factor),
name: order.name,
quantity: order.quantity.mul(factor), quantity: order.quantity.mul(factor),
symbol: order.symbol, symbol: order.symbol,
transactionCount: 1 transactionCount: 1
@ -265,6 +262,7 @@ export class PortfolioCalculator {
} }
const positions: TimelinePosition[] = []; const positions: TimelinePosition[] = [];
for (const item of lastTransactionPoint.items) { for (const item of lastTransactionPoint.items) {
const marketValue = marketSymbolMap[todayString]?.[item.symbol]; const marketValue = marketSymbolMap[todayString]?.[item.symbol];
const isValid = invalidSymbols.indexOf(item.symbol) === -1; const isValid = invalidSymbols.indexOf(item.symbol) === -1;
@ -281,7 +279,6 @@ export class PortfolioCalculator {
: null, : null,
investment: item.investment, investment: item.investment,
marketPrice: marketValue?.toNumber() ?? null, marketPrice: marketValue?.toNumber() ?? null,
name: item.name,
quantity: item.quantity, quantity: item.quantity,
symbol: item.symbol, symbol: item.symbol,
transactionCount: item.transactionCount transactionCount: item.transactionCount

5
apps/api/src/app/order/order.controller.ts

@ -80,6 +80,11 @@ export class OrderController {
include: { include: {
Platform: true Platform: true
} }
},
SymbolProfile: {
select: {
name: true
}
} }
}, },
orderBy: { date: 'desc' }, orderBy: { date: 'desc' },

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

@ -239,7 +239,7 @@ export class PortfolioService {
investment: item.investment.toNumber(), investment: item.investment.toNumber(),
marketPrice: item.marketPrice, marketPrice: item.marketPrice,
marketState: dataProviderResponse.marketState, marketState: dataProviderResponse.marketState,
name: item.name, name: symbolProfile.name,
quantity: item.quantity.toNumber(), quantity: item.quantity.toNumber(),
sectors: symbolProfile.sectors, sectors: symbolProfile.sectors,
symbol: item.symbol, symbol: item.symbol,
@ -438,6 +438,19 @@ export class PortfolioService {
startDate startDate
); );
const symbols = currentPositions.positions.map(
(position) => position.symbol
);
const [symbolProfiles] = await Promise.all([
this.symbolProfileService.getSymbolProfiles(symbols)
]);
const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {};
for (const symbolProfile of symbolProfiles) {
symbolProfileMap[symbolProfile.symbol] = symbolProfile;
}
return { return {
hasErrors: currentPositions.hasErrors, hasErrors: currentPositions.hasErrors,
positions: currentPositions.positions.map((position) => { positions: currentPositions.positions.map((position) => {
@ -448,7 +461,7 @@ export class PortfolioService {
grossPerformancePercentage: grossPerformancePercentage:
position.grossPerformancePercentage?.toNumber() ?? null, position.grossPerformancePercentage?.toNumber() ?? null,
investment: new Big(position.investment).toNumber(), investment: new Big(position.investment).toNumber(),
name: position.name, name: symbolProfileMap[position.symbol].name,
quantity: new Big(position.quantity).toNumber() quantity: new Big(position.quantity).toNumber()
}; };
}) })

7
apps/client/src/app/components/transactions-table/transactions-table.component.html

@ -258,7 +258,12 @@
<tr <tr
*matRowDef="let row; columns: displayedColumns" *matRowDef="let row; columns: displayedColumns"
mat-row mat-row
(click)="onOpenPositionDialog({ symbol: row.symbol, title: '' })" (click)="
onOpenPositionDialog({
symbol: row.symbol,
title: row.SymbolProfile?.name
})
"
></tr> ></tr>
</table> </table>

1
libs/common/src/lib/interfaces/timeline-position.interface.ts

@ -9,7 +9,6 @@ export interface TimelinePosition {
grossPerformancePercentage: Big; grossPerformancePercentage: Big;
investment: Big; investment: Big;
marketPrice: number; marketPrice: number;
name: string;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
transactionCount: number; transactionCount: number;

Loading…
Cancel
Save