Move transaction points to constructor (#3202)

pull/3205/head
Thomas Kaul 3 months ago committed by GitHub
parent 88a9b518f6
commit 5529fdc0ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -49,12 +49,14 @@ export class PortfolioCalculator {
currency, currency,
currentRateService, currentRateService,
exchangeRateDataService, exchangeRateDataService,
orders orders,
transactionPoints
}: { }: {
currency: string; currency: string;
currentRateService: CurrentRateService; currentRateService: CurrentRateService;
exchangeRateDataService: ExchangeRateDataService; exchangeRateDataService: ExchangeRateDataService;
orders: PortfolioOrder[]; orders: PortfolioOrder[];
transactionPoints?: TransactionPoint[];
}) { }) {
this.currency = currency; this.currency = currency;
this.currentRateService = currentRateService; this.currentRateService = currentRateService;
@ -64,6 +66,10 @@ export class PortfolioCalculator {
this.orders.sort((a, b) => { this.orders.sort((a, b) => {
return a.date?.localeCompare(b.date); return a.date?.localeCompare(b.date);
}); });
if (transactionPoints) {
this.transactionPoints = transactionPoints;
}
} }
public computeTransactionPoints() { public computeTransactionPoints() {
@ -179,10 +185,6 @@ export class PortfolioCalculator {
return this.transactionPoints; return this.transactionPoints;
} }
public setTransactionPoints(transactionPoints: TransactionPoint[]) {
this.transactionPoints = transactionPoints;
}
public async getChartData({ public async getChartData({
end = new Date(Date.now()), end = new Date(Date.now()),
start, start,

@ -282,14 +282,13 @@ export class PortfolioService {
} }
const portfolioCalculator = new PortfolioCalculator({ const portfolioCalculator = new PortfolioCalculator({
transactionPoints,
currency: this.request.user.Settings.settings.baseCurrency, currency: this.request.user.Settings.settings.baseCurrency,
currentRateService: this.currentRateService, currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService, exchangeRateDataService: this.exchangeRateDataService,
orders: portfolioOrders orders: portfolioOrders
}); });
portfolioCalculator.setTransactionPoints(transactionPoints);
const { items } = await this.getChart({ const { items } = await this.getChart({
dateRange, dateRange,
impersonationId, impersonationId,
@ -374,14 +373,13 @@ export class PortfolioService {
}); });
const portfolioCalculator = new PortfolioCalculator({ const portfolioCalculator = new PortfolioCalculator({
transactionPoints,
currency: userCurrency, currency: userCurrency,
currentRateService: this.currentRateService, currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService, exchangeRateDataService: this.exchangeRateDataService,
orders: portfolioOrders orders: portfolioOrders
}); });
portfolioCalculator.setTransactionPoints(transactionPoints);
const portfolioStart = parseDate( const portfolioStart = parseDate(
transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT)
); );
@ -999,14 +997,13 @@ export class PortfolioService {
} }
const portfolioCalculator = new PortfolioCalculator({ const portfolioCalculator = new PortfolioCalculator({
transactionPoints,
currency: this.request.user.Settings.settings.baseCurrency, currency: this.request.user.Settings.settings.baseCurrency,
currentRateService: this.currentRateService, currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService, exchangeRateDataService: this.exchangeRateDataService,
orders: portfolioOrders orders: portfolioOrders
}); });
portfolioCalculator.setTransactionPoints(transactionPoints);
const portfolioStart = parseDate(transactionPoints[0].date); const portfolioStart = parseDate(transactionPoints[0].date);
const startDate = this.getStartDate(dateRange, portfolioStart); const startDate = this.getStartDate(dateRange, portfolioStart);
const currentPositions = const currentPositions =
@ -1165,13 +1162,6 @@ export class PortfolioService {
types: withItems ? ['BUY', 'ITEM', 'SELL'] : ['BUY', 'SELL'] types: withItems ? ['BUY', 'ITEM', 'SELL'] : ['BUY', 'SELL']
}); });
const portfolioCalculator = new PortfolioCalculator({
currency: userCurrency,
currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService,
orders: portfolioOrders
});
if (accountBalanceItems?.length <= 0 && transactionPoints?.length <= 0) { if (accountBalanceItems?.length <= 0 && transactionPoints?.length <= 0) {
return { return {
chart: [], chart: [],
@ -1193,7 +1183,13 @@ export class PortfolioService {
}; };
} }
portfolioCalculator.setTransactionPoints(transactionPoints); const portfolioCalculator = new PortfolioCalculator({
transactionPoints,
currency: userCurrency,
currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService,
orders: portfolioOrders
});
const portfolioStart = min( const portfolioStart = min(
[ [
@ -1318,14 +1314,13 @@ export class PortfolioService {
}); });
const portfolioCalculator = new PortfolioCalculator({ const portfolioCalculator = new PortfolioCalculator({
transactionPoints,
currency: userCurrency, currency: userCurrency,
currentRateService: this.currentRateService, currentRateService: this.currentRateService,
exchangeRateDataService: this.exchangeRateDataService, exchangeRateDataService: this.exchangeRateDataService,
orders: portfolioOrders orders: portfolioOrders
}); });
portfolioCalculator.setTransactionPoints(transactionPoints);
const portfolioStart = parseDate( const portfolioStart = parseDate(
transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT)
); );

Loading…
Cancel
Save