Browse Source

Filter by account

pull/5116/head
Thomas Kaul 2 months ago
parent
commit
69da58a4a7
  1. 20
      apps/api/src/app/export/export.service.ts

20
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 { Filter, Export } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Platform } from '@prisma/client'; import { Platform, Prisma } from '@prisma/client';
import { groupBy } from 'lodash';
@Injectable() @Injectable()
export class ExportService { export class ExportService {
@ -26,6 +27,9 @@ export class ExportService {
userCurrency: string; userCurrency: string;
userId: string; userId: string;
}): Promise<Export> { }): Promise<Export> {
const { ACCOUNT: filtersByAccount } = groupBy(filters, ({ type }) => {
return type;
});
const platformsMap: { [platformId: string]: Platform } = {}; const platformsMap: { [platformId: string]: Platform } = {};
let { activities } = await this.orderService.getOrders({ 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 = ( const accounts = (
await this.accountService.accounts({ await this.accountService.accounts({
where,
include: { include: {
balances: true, balances: true,
platform: true platform: true
}, },
orderBy: { orderBy: {
name: 'asc' name: 'asc'
}, }
where: { userId }
}) })
) )
.filter(({ id }) => { .filter(({ id }) => {

Loading…
Cancel
Save