|
@ -1,11 +1,15 @@ |
|
|
|
|
|
import { AccountService } from '@ghostfolio/api/app/account/account.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 { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
|
|
|
import { Export } from '@ghostfolio/common/interfaces'; |
|
|
import { Export } from '@ghostfolio/common/interfaces'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class ExportService { |
|
|
export class ExportService { |
|
|
public constructor(private readonly prismaService: PrismaService) {} |
|
|
public constructor( |
|
|
|
|
|
private readonly accountService: AccountService, |
|
|
|
|
|
private readonly orderService: OrderService |
|
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
public async export({ |
|
|
public async export({ |
|
|
activityIds, |
|
|
activityIds, |
|
@ -14,36 +18,40 @@ export class ExportService { |
|
|
activityIds?: string[]; |
|
|
activityIds?: string[]; |
|
|
userId: string; |
|
|
userId: string; |
|
|
}): Promise<Export> { |
|
|
}): Promise<Export> { |
|
|
const accounts = await this.prismaService.account.findMany({ |
|
|
const accounts = ( |
|
|
|
|
|
await this.accountService.accounts({ |
|
|
orderBy: { |
|
|
orderBy: { |
|
|
name: 'asc' |
|
|
name: 'asc' |
|
|
}, |
|
|
}, |
|
|
select: { |
|
|
|
|
|
accountType: true, |
|
|
|
|
|
balance: true, |
|
|
|
|
|
comment: true, |
|
|
|
|
|
currency: true, |
|
|
|
|
|
id: true, |
|
|
|
|
|
isExcluded: true, |
|
|
|
|
|
name: true, |
|
|
|
|
|
platformId: true |
|
|
|
|
|
}, |
|
|
|
|
|
where: { userId } |
|
|
where: { userId } |
|
|
}); |
|
|
}) |
|
|
|
|
|
).map( |
|
|
|
|
|
({ |
|
|
|
|
|
accountType, |
|
|
|
|
|
balance, |
|
|
|
|
|
comment, |
|
|
|
|
|
currency, |
|
|
|
|
|
id, |
|
|
|
|
|
isExcluded, |
|
|
|
|
|
name, |
|
|
|
|
|
platformId |
|
|
|
|
|
}) => { |
|
|
|
|
|
return { |
|
|
|
|
|
accountType, |
|
|
|
|
|
balance, |
|
|
|
|
|
comment, |
|
|
|
|
|
currency, |
|
|
|
|
|
id, |
|
|
|
|
|
isExcluded, |
|
|
|
|
|
name, |
|
|
|
|
|
platformId |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
let activities = await this.prismaService.order.findMany({ |
|
|
let activities = await this.orderService.orders({ |
|
|
|
|
|
include: { SymbolProfile: true }, |
|
|
orderBy: { date: 'desc' }, |
|
|
orderBy: { date: 'desc' }, |
|
|
select: { |
|
|
|
|
|
accountId: true, |
|
|
|
|
|
comment: true, |
|
|
|
|
|
date: true, |
|
|
|
|
|
fee: true, |
|
|
|
|
|
id: true, |
|
|
|
|
|
quantity: true, |
|
|
|
|
|
SymbolProfile: true, |
|
|
|
|
|
type: true, |
|
|
|
|
|
unitPrice: true |
|
|
|
|
|
}, |
|
|
|
|
|
where: { userId } |
|
|
where: { userId } |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|