diff --git a/apps/api/src/app/account/account.controller.ts b/apps/api/src/app/account/account.controller.ts index f612fd0f8..4666e5084 100644 --- a/apps/api/src/app/account/account.controller.ts +++ b/apps/api/src/app/account/account.controller.ts @@ -1,8 +1,12 @@ import { PortfolioService } from '@ghostfolio/api/app/portfolio/portfolio.service'; import { RedactValuesInResponseInterceptor } from '@ghostfolio/api/interceptors/redact-values-in-response.interceptor'; +import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; import { ImpersonationService } from '@ghostfolio/api/services/impersonation/impersonation.service'; import { HEADER_KEY_IMPERSONATION } from '@ghostfolio/common/config'; -import { Accounts } from '@ghostfolio/common/interfaces'; +import { + AccountBalancesResponse, + Accounts +} from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import type { AccountWithValue, @@ -31,8 +35,6 @@ import { AccountService } from './account.service'; import { CreateAccountDto } from './create-account.dto'; import { TransferBalanceDto } from './transfer-balance.dto'; import { UpdateAccountDto } from './update-account.dto'; -import { AccountBalances } from './interfaces/account-balances.interface'; -import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; @Controller('account') export class AccountController { @@ -42,7 +44,7 @@ export class AccountController { private readonly impersonationService: ImpersonationService, private readonly portfolioService: PortfolioService, @Inject(REQUEST) private readonly request: RequestWithUser - ) { } + ) {} @Delete(':id') @UseGuards(AuthGuard('jwt')) @@ -124,7 +126,7 @@ export class AccountController { @UseInterceptors(RedactValuesInResponseInterceptor) public async getAccountBalancesById( @Param('id') id: string - ): Promise { + ): Promise { return this.accountBalanceService.getAccountBalances({ accountId: id, userId: this.request.user.id diff --git a/apps/api/src/app/account/interfaces/account-balances.interface.ts b/apps/api/src/app/account/interfaces/account-balances.interface.ts deleted file mode 100644 index dd1cc3193..000000000 --- a/apps/api/src/app/account/interfaces/account-balances.interface.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface AccountBalances { - balances: AccountBalance[]; -} - -export interface AccountBalance { - date: Date; - id: string; - value: number; -} diff --git a/apps/api/src/services/account-balance/account-balance.service.ts b/apps/api/src/services/account-balance/account-balance.service.ts index 5847f9d8e..9995bbc3e 100644 --- a/apps/api/src/services/account-balance/account-balance.service.ts +++ b/apps/api/src/services/account-balance/account-balance.service.ts @@ -1,11 +1,11 @@ -import { AccountBalances } from '@ghostfolio/api/app/account/interfaces/account-balances.interface'; import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; +import { AccountBalancesResponse } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; import { AccountBalance, Prisma } from '@prisma/client'; @Injectable() export class AccountBalanceService { - public constructor(private readonly prismaService: PrismaService) { } + public constructor(private readonly prismaService: PrismaService) {} public async createAccountBalance( data: Prisma.AccountBalanceCreateInput @@ -21,8 +21,11 @@ export class AccountBalanceService { }: { accountId: string; userId: string; - }): Promise { + }): Promise { const balances = await this.prismaService.accountBalance.findMany({ + orderBy: { + date: 'asc' + }, select: { date: true, id: true, diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts index e33b6b55f..47df3d2f9 100644 --- a/libs/common/src/lib/interfaces/index.ts +++ b/libs/common/src/lib/interfaces/index.ts @@ -33,6 +33,7 @@ import type { PortfolioReport } from './portfolio-report.interface'; import type { PortfolioSummary } from './portfolio-summary.interface'; import type { Position } from './position.interface'; import type { Product } from './product'; +import type { AccountBalancesResponse } from './responses/account-balances-response.interface'; import type { BenchmarkResponse } from './responses/benchmark-response.interface'; import type { ResponseError } from './responses/errors.interface'; import type { ImportResponse } from './responses/import-response.interface'; @@ -49,6 +50,7 @@ import type { User } from './user.interface'; export { Access, + AccountBalancesResponse, Accounts, AdminData, AdminJobs, diff --git a/libs/common/src/lib/interfaces/responses/account-balances-response.interface.ts b/libs/common/src/lib/interfaces/responses/account-balances-response.interface.ts new file mode 100644 index 000000000..9b4ec2f6d --- /dev/null +++ b/libs/common/src/lib/interfaces/responses/account-balances-response.interface.ts @@ -0,0 +1,5 @@ +import { AccountBalance } from '@prisma/client'; + +export interface AccountBalancesResponse { + balances: Pick[]; +}