From 2f35f7225fa70f917726f51e3101abc5745c38b4 Mon Sep 17 00:00:00 2001 From: Sayed Murtadha Ahmed <sayed.m.ahmed@array.world> Date: Thu, 27 Feb 2025 22:59:12 +0300 Subject: [PATCH] Feature/extend export by platforms (#4360) * Extend export by platforms * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/export/export.service.ts | 26 ++++++++++++++++++- .../src/lib/interfaces/export.interface.ts | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b99b790..2d57e73d3 100644 --- a/CHANGELOG.md +++ b/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 platforms - Extended the _Trackinsight_ data enhancer for asset profile data by `cusip` - Added _Storybook_ to the build process diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index 219ffffda..8d7585c01 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -5,6 +5,7 @@ import { TagService } from '@ghostfolio/api/services/tag/tag.service'; import { Filter, Export } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; +import { Platform } from '@prisma/client'; @Injectable() export class ExportService { @@ -25,15 +26,37 @@ export class ExportService { userCurrency: string; userId: string; }): Promise<Export> { + const platforms: Platform[] = []; + const accounts = ( await this.accountService.accounts({ + include: { + Platform: true + }, orderBy: { name: 'asc' }, where: { userId } }) ).map( - ({ balance, comment, currency, id, isExcluded, name, platformId }) => { + ({ + balance, + comment, + currency, + id, + isExcluded, + name, + platformId, + Platform: platform + }) => { + if ( + !platforms.some(({ id: currentPlatformId }) => { + return currentPlatformId === platform.id; + }) + ) { + platforms.push(platform); + } + return { balance, comment, @@ -76,6 +99,7 @@ export class ExportService { return { meta: { date: new Date().toISOString(), version: environment.version }, accounts, + platforms, tags, activities: activities.map( ({ diff --git a/libs/common/src/lib/interfaces/export.interface.ts b/libs/common/src/lib/interfaces/export.interface.ts index 1257e50bc..14a017428 100644 --- a/libs/common/src/lib/interfaces/export.interface.ts +++ b/libs/common/src/lib/interfaces/export.interface.ts @@ -1,4 +1,4 @@ -import { Account, Order, Tag } from '@prisma/client'; +import { Account, Order, Platform, Tag } from '@prisma/client'; export interface Export { accounts: Omit<Account, 'createdAt' | 'updatedAt' | 'userId'>[]; @@ -16,6 +16,7 @@ export interface Export { date: string; version: string; }; + platforms: Platform[]; tags: Omit<Tag, 'userId'>[]; user: { settings: { currency: string } }; }