diff --git a/apps/api/src/app/export/export.module.ts b/apps/api/src/app/export/export.module.ts index 186e8dc59..ca4588925 100644 --- a/apps/api/src/app/export/export.module.ts +++ b/apps/api/src/app/export/export.module.ts @@ -1,8 +1,9 @@ +import { AccountModule } from '@ghostfolio/api/app/account/account.module'; +import { OrderModule } from '@ghostfolio/api/app/order/order.module'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering/data-gathering.module'; import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; -import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; import { Module } from '@nestjs/common'; import { ExportController } from './export.controller'; @@ -10,10 +11,11 @@ import { ExportService } from './export.service'; @Module({ imports: [ + AccountModule, ConfigurationModule, DataGatheringModule, DataProviderModule, - PrismaModule, + OrderModule, RedisCacheModule ], controllers: [ExportController], diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index eaeea0f07..abeaf389d 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -1,11 +1,15 @@ +import { AccountService } from '@ghostfolio/api/app/account/account.service'; +import { OrderService } from '@ghostfolio/api/app/order/order.service'; import { environment } from '@ghostfolio/api/environments/environment'; -import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; import { Export } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; @Injectable() export class ExportService { - public constructor(private readonly prismaService: PrismaService) {} + public constructor( + private readonly accountService: AccountService, + private readonly orderService: OrderService + ) {} public async export({ activityIds, @@ -14,36 +18,40 @@ export class ExportService { activityIds?: string[]; userId: string; }): Promise { - const accounts = await this.prismaService.account.findMany({ - orderBy: { - name: 'asc' - }, - select: { - accountType: true, - balance: true, - comment: true, - currency: true, - id: true, - isExcluded: true, - name: true, - platformId: true - }, - where: { userId } - }); + const accounts = ( + await this.accountService.accounts({ + orderBy: { + name: 'asc' + }, + where: { userId } + }) + ).map( + ({ + accountType, + balance, + comment, + currency, + id, + isExcluded, + name, + platformId + }) => { + return { + accountType, + balance, + comment, + currency, + id, + isExcluded, + name, + platformId + }; + } + ); - let activities = await this.prismaService.order.findMany({ + let activities = await this.orderService.orders({ + include: { SymbolProfile: true }, orderBy: { date: 'desc' }, - select: { - accountId: true, - comment: true, - date: true, - fee: true, - id: true, - quantity: true, - SymbolProfile: true, - type: true, - unitPrice: true - }, where: { userId } });