|
@ -1,6 +1,7 @@ |
|
|
import { AccountService } from '@ghostfolio/api/app/account/account.service'; |
|
|
import { AccountService } from '@ghostfolio/api/app/account/account.service'; |
|
|
import { OrderService } from '@ghostfolio/api/app/order/order.service'; |
|
|
import { OrderService } from '@ghostfolio/api/app/order/order.service'; |
|
|
import { environment } from '@ghostfolio/api/environments/environment'; |
|
|
import { environment } from '@ghostfolio/api/environments/environment'; |
|
|
|
|
|
import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service'; |
|
|
import { TagService } from '@ghostfolio/api/services/tag/tag.service'; |
|
|
import { TagService } from '@ghostfolio/api/services/tag/tag.service'; |
|
|
import { Filter, Export } from '@ghostfolio/common/interfaces'; |
|
|
import { Filter, Export } from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
|
|
@ -12,6 +13,7 @@ import { groupBy, uniqBy } from 'lodash'; |
|
|
export class ExportService { |
|
|
export class ExportService { |
|
|
public constructor( |
|
|
public constructor( |
|
|
private readonly accountService: AccountService, |
|
|
private readonly accountService: AccountService, |
|
|
|
|
|
private readonly marketDataService: MarketDataService, |
|
|
private readonly orderService: OrderService, |
|
|
private readonly orderService: OrderService, |
|
|
private readonly tagService: TagService |
|
|
private readonly tagService: TagService |
|
|
) {} |
|
|
) {} |
|
@ -108,15 +110,36 @@ export class ExportService { |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const assetProfiles = uniqBy( |
|
|
const customAssetProfiles = uniqBy( |
|
|
activities.map(({ SymbolProfile }) => { |
|
|
activities |
|
|
|
|
|
.map(({ SymbolProfile }) => { |
|
|
return SymbolProfile; |
|
|
return SymbolProfile; |
|
|
|
|
|
}) |
|
|
|
|
|
.filter(({ userId: assetProfileUserId }) => { |
|
|
|
|
|
return assetProfileUserId === userId; |
|
|
}), |
|
|
}), |
|
|
({ id }) => { |
|
|
({ id }) => { |
|
|
return id; |
|
|
return id; |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const marketDataByAssetProfile = Object.fromEntries( |
|
|
|
|
|
await Promise.all( |
|
|
|
|
|
customAssetProfiles.map(async ({ dataSource, id, symbol }) => { |
|
|
|
|
|
const marketData = ( |
|
|
|
|
|
await this.marketDataService.marketDataItems({ |
|
|
|
|
|
where: { dataSource, symbol } |
|
|
|
|
|
}) |
|
|
|
|
|
).map(({ date, marketPrice }) => ({ |
|
|
|
|
|
date: date.toISOString(), |
|
|
|
|
|
marketPrice |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
return [id, marketData] as const; |
|
|
|
|
|
}) |
|
|
|
|
|
) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const tags = (await this.tagService.getTagsForUser(userId)) |
|
|
const tags = (await this.tagService.getTagsForUser(userId)) |
|
|
.filter( |
|
|
.filter( |
|
|
({ id, isUsed }) => |
|
|
({ id, isUsed }) => |
|
@ -137,7 +160,7 @@ export class ExportService { |
|
|
return { |
|
|
return { |
|
|
meta: { date: new Date().toISOString(), version: environment.version }, |
|
|
meta: { date: new Date().toISOString(), version: environment.version }, |
|
|
accounts, |
|
|
accounts, |
|
|
assetProfiles: assetProfiles.map( |
|
|
assetProfiles: customAssetProfiles.map( |
|
|
({ |
|
|
({ |
|
|
assetClass, |
|
|
assetClass, |
|
|
assetSubClass, |
|
|
assetSubClass, |
|
@ -175,6 +198,7 @@ export class ExportService { |
|
|
id, |
|
|
id, |
|
|
isActive, |
|
|
isActive, |
|
|
isin, |
|
|
isin, |
|
|
|
|
|
marketData: marketDataByAssetProfile[id], |
|
|
name, |
|
|
name, |
|
|
scraperConfiguration: |
|
|
scraperConfiguration: |
|
|
scraperConfiguration as unknown as Prisma.JsonArray, |
|
|
scraperConfiguration as unknown as Prisma.JsonArray, |
|
|