Browse Source

Feature/extend export by account balances (#4390)

* Extend export by account balances

* Update changelog
pull/4414/head
csehatt741 2 weeks ago
committed by GitHub
parent
commit
cb1f488eb4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 20
      apps/api/src/app/account/account.service.ts
  3. 5
      apps/api/src/app/export/export.service.ts
  4. 4
      libs/common/src/lib/interfaces/export.interface.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Extended the export functionality by the account balances
- Added a _Copy portfolio data to clipboard for AI prompt_ action to the analysis page (experimental)
### Changed

20
apps/api/src/app/account/account.service.ts

@ -7,7 +7,13 @@ import { Filter } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Account, Order, Platform, Prisma } from '@prisma/client';
import {
Account,
AccountBalance,
Order,
Platform,
Prisma
} from '@prisma/client';
import { Big } from 'big.js';
import { format } from 'date-fns';
import { groupBy } from 'lodash';
@ -56,13 +62,19 @@ export class AccountService {
orderBy?: Prisma.AccountOrderByWithRelationInput;
}): Promise<
(Account & {
balances?: AccountBalance[];
Order?: Order[];
Platform?: Platform;
})[]
> {
const { include = {}, skip, take, cursor, where, orderBy } = params;
include.balances = { orderBy: { date: 'desc' }, take: 1 };
const isBalancesIncluded = !!include.balances;
include.balances = {
orderBy: { date: 'desc' },
...(isBalancesIncluded ? {} : { take: 1 })
};
const accounts = await this.prismaService.account.findMany({
cursor,
@ -76,7 +88,9 @@ export class AccountService {
return accounts.map((account) => {
account = { ...account, balance: account.balances[0]?.value ?? 0 };
delete account.balances;
if (!isBalancesIncluded) {
delete account.balances;
}
return account;
});

5
apps/api/src/app/export/export.service.ts

@ -31,6 +31,7 @@ export class ExportService {
const accounts = (
await this.accountService.accounts({
include: {
balances: true,
Platform: true
},
orderBy: {
@ -41,6 +42,7 @@ export class ExportService {
).map(
({
balance,
balances,
comment,
currency,
id,
@ -55,6 +57,9 @@ export class ExportService {
return {
balance,
balances: balances.map(({ date, value }) => {
return { date: date.toISOString(), value };
}),
comment,
currency,
id,

4
libs/common/src/lib/interfaces/export.interface.ts

@ -1,7 +1,9 @@
import { Account, Order, Platform, Tag } from '@prisma/client';
export interface Export {
accounts: Omit<Account, 'createdAt' | 'updatedAt' | 'userId'>[];
accounts: (Omit<Account, 'createdAt' | 'updatedAt' | 'userId'> & {
balances: { date: string; value: number }[];
})[];
activities: (Omit<
Order,
| 'accountUserId'

Loading…
Cancel
Save