From 69da58a4a7d465ac76dec9aa2385195a7e5b3bd3 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 8 Jul 2025 20:12:54 +0200 Subject: [PATCH] Filter by account --- apps/api/src/app/export/export.service.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index 57991fe14..f0f52bfe2 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -5,7 +5,8 @@ import { TagService } from '@ghostfolio/api/services/tag/tag.service'; import { Filter, Export } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; -import { Platform } from '@prisma/client'; +import { Platform, Prisma } from '@prisma/client'; +import { groupBy } from 'lodash'; @Injectable() export class ExportService { @@ -26,6 +27,9 @@ export class ExportService { userCurrency: string; userId: string; }): Promise { + const { ACCOUNT: filtersByAccount } = groupBy(filters, ({ type }) => { + return type; + }); const platformsMap: { [platformId: string]: Platform } = {}; let { activities } = await this.orderService.getOrders({ @@ -44,16 +48,26 @@ export class ExportService { }); } + const where: Prisma.AccountWhereInput = { userId }; + + if (filtersByAccount?.length > 0) { + where.id = { + in: filtersByAccount.map(({ id }) => { + return id; + }) + }; + } + const accounts = ( await this.accountService.accounts({ + where, include: { balances: true, platform: true }, orderBy: { name: 'asc' - }, - where: { userId } + } }) ) .filter(({ id }) => {