Browse Source

Feature/extend export by platforms

pull/4360/head
Sayed Murtadha Ahmed 2 months ago
parent
commit
9ed483f5c9
  1. 1
      CHANGELOG.md
  2. 25
      apps/api/src/app/export/export.service.ts
  3. 3
      libs/common/src/lib/interfaces/export.interface.ts

1
CHANGELOG.md

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extended the portfolio snapshot in the portfolio calculator by the activities count
- Extended the user endpoint `GET api/v1/user` by the activities count
- Added `cusip` to the asset profile model
- Extended the export functionality by the platforms
### Changed

25
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,36 @@ 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: currentId }) => {
return currentId === platform.id;
})
) {
platforms.push(platform);
}
return {
balance,
comment,
@ -76,6 +98,7 @@ export class ExportService {
return {
meta: { date: new Date().toISOString(), version: environment.version },
accounts,
platforms,
tags,
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 {
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 } };
}

Loading…
Cancel
Save