Feature/extend export by account balances (#4390)
* Extend export by account balances * Update changelog
This commit is contained in:
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### 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)
|
- Added a _Copy portfolio data to clipboard for AI prompt_ action to the analysis page (experimental)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -7,7 +7,13 @@ import { Filter } from '@ghostfolio/common/interfaces';
|
|||||||
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
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 { Big } from 'big.js';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import { groupBy } from 'lodash';
|
import { groupBy } from 'lodash';
|
||||||
@ -56,13 +62,19 @@ export class AccountService {
|
|||||||
orderBy?: Prisma.AccountOrderByWithRelationInput;
|
orderBy?: Prisma.AccountOrderByWithRelationInput;
|
||||||
}): Promise<
|
}): Promise<
|
||||||
(Account & {
|
(Account & {
|
||||||
|
balances?: AccountBalance[];
|
||||||
Order?: Order[];
|
Order?: Order[];
|
||||||
Platform?: Platform;
|
Platform?: Platform;
|
||||||
})[]
|
})[]
|
||||||
> {
|
> {
|
||||||
const { include = {}, skip, take, cursor, where, orderBy } = params;
|
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({
|
const accounts = await this.prismaService.account.findMany({
|
||||||
cursor,
|
cursor,
|
||||||
@ -76,7 +88,9 @@ export class AccountService {
|
|||||||
return accounts.map((account) => {
|
return accounts.map((account) => {
|
||||||
account = { ...account, balance: account.balances[0]?.value ?? 0 };
|
account = { ...account, balance: account.balances[0]?.value ?? 0 };
|
||||||
|
|
||||||
delete account.balances;
|
if (!isBalancesIncluded) {
|
||||||
|
delete account.balances;
|
||||||
|
}
|
||||||
|
|
||||||
return account;
|
return account;
|
||||||
});
|
});
|
||||||
|
@ -31,6 +31,7 @@ export class ExportService {
|
|||||||
const accounts = (
|
const accounts = (
|
||||||
await this.accountService.accounts({
|
await this.accountService.accounts({
|
||||||
include: {
|
include: {
|
||||||
|
balances: true,
|
||||||
Platform: true
|
Platform: true
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
@ -41,6 +42,7 @@ export class ExportService {
|
|||||||
).map(
|
).map(
|
||||||
({
|
({
|
||||||
balance,
|
balance,
|
||||||
|
balances,
|
||||||
comment,
|
comment,
|
||||||
currency,
|
currency,
|
||||||
id,
|
id,
|
||||||
@ -55,6 +57,9 @@ export class ExportService {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
balance,
|
balance,
|
||||||
|
balances: balances.map(({ date, value }) => {
|
||||||
|
return { date: date.toISOString(), value };
|
||||||
|
}),
|
||||||
comment,
|
comment,
|
||||||
currency,
|
currency,
|
||||||
id,
|
id,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { Account, Order, Platform, Tag } from '@prisma/client';
|
import { Account, Order, Platform, Tag } from '@prisma/client';
|
||||||
|
|
||||||
export interface Export {
|
export interface Export {
|
||||||
accounts: Omit<Account, 'createdAt' | 'updatedAt' | 'userId'>[];
|
accounts: (Omit<Account, 'createdAt' | 'updatedAt' | 'userId'> & {
|
||||||
|
balances: { date: string; value: number }[];
|
||||||
|
})[];
|
||||||
activities: (Omit<
|
activities: (Omit<
|
||||||
Order,
|
Order,
|
||||||
| 'accountUserId'
|
| 'accountUserId'
|
||||||
|
Reference in New Issue
Block a user