Browse Source

Feature/extend export by platforms (#4360)

* Extend export by platforms

* Update changelog
pull/4372/head
Sayed Murtadha Ahmed 1 month ago
committed by GitHub
parent
commit
2f35f7225f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 26
      apps/api/src/app/export/export.service.ts
  3. 3
      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 ### Added
- Extended the export functionality by the platforms
- Extended the _Trackinsight_ data enhancer for asset profile data by `cusip` - Extended the _Trackinsight_ data enhancer for asset profile data by `cusip`
- Added _Storybook_ to the build process - Added _Storybook_ to the build process

26
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 { Filter, Export } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Platform } from '@prisma/client';
@Injectable() @Injectable()
export class ExportService { export class ExportService {
@ -25,15 +26,37 @@ export class ExportService {
userCurrency: string; userCurrency: string;
userId: string; userId: string;
}): Promise<Export> { }): Promise<Export> {
const platforms: Platform[] = [];
const accounts = ( const accounts = (
await this.accountService.accounts({ await this.accountService.accounts({
include: {
Platform: true
},
orderBy: { orderBy: {
name: 'asc' name: 'asc'
}, },
where: { userId } where: { userId }
}) })
).map( ).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 { return {
balance, balance,
comment, comment,
@ -76,6 +99,7 @@ export class ExportService {
return { return {
meta: { date: new Date().toISOString(), version: environment.version }, meta: { date: new Date().toISOString(), version: environment.version },
accounts, accounts,
platforms,
tags, tags,
activities: activities.map( activities: activities.map(
({ ({

3
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 { export interface Export {
accounts: Omit<Account, 'createdAt' | 'updatedAt' | 'userId'>[]; accounts: Omit<Account, 'createdAt' | 'updatedAt' | 'userId'>[];
@ -16,6 +16,7 @@ export interface Export {
date: string; date: string;
version: string; version: string;
}; };
platforms: Platform[];
tags: Omit<Tag, 'userId'>[]; tags: Omit<Tag, 'userId'>[];
user: { settings: { currency: string } }; user: { settings: { currency: string } };
} }

Loading…
Cancel
Save