Browse Source

Refactor item type (#3119)

pull/3112/head^2
Thomas Kaul 7 months ago
committed by GitHub
parent
commit
b642ce08e5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      apps/api/src/app/portfolio/interfaces/portfolio-calculator.interface.ts
  2. 22
      apps/api/src/app/portfolio/portfolio-calculator.ts

2
apps/api/src/app/portfolio/interfaces/portfolio-calculator.interface.ts

@ -5,7 +5,7 @@ import { PortfolioOrder } from './portfolio-order.interface';
export interface PortfolioOrderItem extends PortfolioOrder { export interface PortfolioOrderItem extends PortfolioOrder {
feeInBaseCurrency?: Big; feeInBaseCurrency?: Big;
feeInBaseCurrencyWithCurrencyEffect?: Big; feeInBaseCurrencyWithCurrencyEffect?: Big;
itemType?: '' | 'start' | 'end'; itemType?: 'end' | 'start';
unitPriceInBaseCurrency?: Big; unitPriceInBaseCurrency?: Big;
unitPriceInBaseCurrencyWithCurrencyEffect?: Big; unitPriceInBaseCurrencyWithCurrencyEffect?: Big;
} }

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

@ -1049,28 +1049,26 @@ export class PortfolioCalculator {
} }
} }
// Sort orders so that the start and end placeholder order are at the right // Sort orders so that the start and end placeholder order are at the correct
// position // position
orders = sortBy(orders, (order) => { orders = sortBy(orders, ({ date, itemType }) => {
let sortIndex = new Date(order.date); let sortIndex = new Date(date);
if (order.itemType === 'start') { if (itemType === 'end') {
sortIndex = addMilliseconds(sortIndex, -1);
}
if (order.itemType === 'end') {
sortIndex = addMilliseconds(sortIndex, 1); sortIndex = addMilliseconds(sortIndex, 1);
} else if (itemType === 'start') {
sortIndex = addMilliseconds(sortIndex, -1);
} }
return sortIndex.getTime(); return sortIndex.getTime();
}); });
const indexOfStartOrder = orders.findIndex((order) => { const indexOfStartOrder = orders.findIndex(({ itemType }) => {
return order.itemType === 'start'; return itemType === 'start';
}); });
const indexOfEndOrder = orders.findIndex((order) => { const indexOfEndOrder = orders.findIndex(({ itemType }) => {
return order.itemType === 'end'; return itemType === 'end';
}); });
let totalInvestmentDays = 0; let totalInvestmentDays = 0;

Loading…
Cancel
Save