From 2698b13a2130d82ca5564b6e563a6fb5c2f479e5 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 10 Oct 2026 10:07:20 +0200 Subject: [PATCH] Add groupBy=year to portfolio performance endpoint --- .../app/portfolio/portfolio.service.spec.ts | 32 ------------------- .../src/app/portfolio/portfolio.service.ts | 23 ++++++------- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.spec.ts b/apps/api/src/app/portfolio/portfolio.service.spec.ts index e4c0049cec..f562966b06 100644 --- a/apps/api/src/app/portfolio/portfolio.service.spec.ts +++ b/apps/api/src/app/portfolio/portfolio.service.spec.ts @@ -1158,38 +1158,6 @@ describe('PortfolioService', () => { { date: '2025-01-01', investmentValueWithCurrencyEffect: 200 } ]); }); - - it('should skip a calendar year without a chart when grouped by year', async () => { - getPerformanceOfCalculator - .mockResolvedValueOnce({ - chart: [ - { date: '2023-12-31', netPerformance: 0 }, - { date: '2024-12-31', netPerformance: 200 }, - { date: '2025-06-15', netPerformance: 300 } - ] - }) - .mockResolvedValueOnce({ chart: [] }) - .mockResolvedValueOnce({ - chart: [ - { date: '2024-12-31', netPerformance: 0 }, - { date: '2025-06-15', netPerformance: 100 } - ] - }); - - const { chart } = await portfolioService.getPerformance({ - dateRange: 'max', - groupBy: 'year', - userId: userDummyData.id - }); - - expect(chart).toEqual([ - { - date: '2025-01-01', - investmentValueWithCurrencyEffect: 0, - netPerformance: 100 - } - ]); - }); }); describe('getSummary', () => { diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 5f31cabfca..8aea5ef0db 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -2065,15 +2065,14 @@ export class PortfolioService { } /** - * Returns one chart item per calendar year of the date range, like the - * dividends and the investments grouped by year, dated on 1 January. Each - * year stands alone and is not accumulated, so its values are the same as - * for the date range of the year (e.g. '2024'), clipped to the requested - * date range. The investment is the sum of the year, the other values are - * the ones at the end of the year. The first chart item of the date range - * carries the values at its start date and belongs to the previous period, - * like 31 December for a calendar year, so the years before the first - * activity have no chart item. + * Returns one chart item per calendar year of the date range, dated on + * 1 January. Each year stands alone and is not accumulated, so its values + * are the same as for the date range of the year (e.g. '2024'), clipped to + * the requested date range. The investment is the sum of the year, the other + * values are the ones at the end of the year. The first chart item of the + * date range carries the values at its start date and belongs to the + * previous period, like 31 December for a calendar year, so the years before + * the first activity have no chart item. */ private async getPerformanceByYear({ chartOfDateRange, @@ -2089,7 +2088,7 @@ export class PortfolioService { const chart: HistoricalDataItem[] = []; const years = uniq( - chartOfDateRange?.slice(1).map(({ date }) => { + chartOfDateRange.slice(1).map(({ date }) => { return date.substring(0, 4); }) ); @@ -2103,10 +2102,6 @@ export class PortfolioService { start: index === 0 ? startDate : startDateOfYear }); - if (!chartOfYear?.length) { - continue; - } - let investmentValueWithCurrencyEffect = new Big(0); for (const historicalDataItem of chartOfYear.slice(1)) {