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;
firstBuyDate: string;
investment: Big;
name: string;
quantity: Big;
symbol: string;
transactionCount: number;

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

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

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

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

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

@ -239,7 +239,7 @@ export class PortfolioService {
investment: item.investment.toNumber(),
marketPrice: item.marketPrice,
marketState: dataProviderResponse.marketState,
name: item.name,
name: symbolProfile.name,
quantity: item.quantity.toNumber(),
sectors: symbolProfile.sectors,
symbol: item.symbol,
@ -438,6 +438,19 @@ export class PortfolioService {
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 {
hasErrors: currentPositions.hasErrors,
positions: currentPositions.positions.map((position) => {
@ -448,7 +461,7 @@ export class PortfolioService {
grossPerformancePercentage:
position.grossPerformancePercentage?.toNumber() ?? null,
investment: new Big(position.investment).toNumber(),
name: position.name,
name: symbolProfileMap[position.symbol].name,
quantity: new Big(position.quantity).toNumber()
};
})

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

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

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

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

Loading…
Cancel
Save