|
@ -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( |
|
|
({ |
|
|
({ |
|
|