feat: extend account list portfolio summary (#138) #139

Merged
codex-bot merged 3 commits from feature/138-account-list-summary into develop 2026-10-27 05:44:08 +03:00
2 changed files with 10 additions and 7 deletions
Showing only changes of commit 02880ed579 - Show all commits
@@ -111,15 +111,17 @@ describe('saved brokerage account projection', () => {
{ type: 'FUND', quantity: '3', averagePurchasePrice: { currency: 'USD', value: '2.5' }, absoluteReturn: null }, { type: 'FUND', quantity: '3', averagePurchasePrice: { currency: 'USD', value: '2.5' }, absoluteReturn: null },
{ type: 'STOCK', quantity: '4', averagePurchasePrice: { currency: 'USD', value: '0' }, absoluteReturn: { currency: 'USD', value: '2.5' } }, { type: 'STOCK', quantity: '4', averagePurchasePrice: { currency: 'USD', value: '0' }, absoluteReturn: { currency: 'USD', value: '2.5' } },
{ type: 'CURRENCY', quantity: '100', averagePurchasePrice: { currency: 'EUR', value: '1' }, absoluteReturn: { currency: 'EUR', value: '5' } }, { type: 'CURRENCY', quantity: '100', averagePurchasePrice: { currency: 'EUR', value: '1' }, absoluteReturn: { currency: 'EUR', value: '5' } },
{ type: 'BOND', quantity: '1', currentValue: { currency: 'CNY', value: '7' }, averagePurchasePrice: null, absoluteReturn: null },
], ],
}, },
}], }],
}); });
expect((await service.list('owner')).data?.[0].portfolioSummary).toMatchObject({ expect((await service.list('owner')).data?.[0].portfolioSummary).toMatchObject({
stockPositionCount: 2, bondPositionCount: 1, stockPositionCount: 2, bondPositionCount: 2,
fundPositionCount: 1, totalPositionCount: 5, fundPositionCount: 1, totalPositionCount: 6,
unrealizedReturnByCurrency: [ unrealizedReturnByCurrency: [
{ currency: 'CNY', absolute: '0', costBasis: '0', percent: null, partial: true },
{ currency: 'RUB', absolute: '1.250000003', costBasis: '30.000000002', percent: '4.17', partial: false }, { currency: 'RUB', absolute: '1.250000003', costBasis: '30.000000002', percent: '4.17', partial: false },
{ currency: 'USD', absolute: '2.5', costBasis: '0', percent: null, partial: true }, { currency: 'USD', absolute: '2.5', costBasis: '0', percent: null, partial: true },
], ],
@@ -40,11 +40,12 @@ function unrealizedReturns(positions: PortfolioPositionDto[]): UnrealizedReturnD
), ),
); );
const partial = new Set( const partial = new Set(
investments.flatMap((position) => investments.flatMap((position) => {
!position.absoluteReturn && position.averagePurchasePrice const money = position.absoluteReturn
? [position.averagePurchasePrice.currency] ? null
: [], : position.averagePurchasePrice ?? position.currentValue;
), return money ? [money.currency] : [];
}),
); );
const currencies = new Set([...absolute, ...costs].map((money) => money.currency)); const currencies = new Set([...absolute, ...costs].map((money) => money.currency));
return [...new Set([...currencies, ...partial])] return [...new Set([...currencies, ...partial])]