ghostfolio/apps/api/src/app/export/export.service.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

import { environment } from '@ghostfolio/api/environments/environment';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { Export } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common';
@Injectable()
export class ExportService {
2021-08-07 22:38:07 +02:00
public constructor(private readonly prismaService: PrismaService) {}
public async export({ userId }: { userId: string }): Promise<Export> {
2021-08-07 22:38:07 +02:00
const orders = await this.prismaService.order.findMany({
orderBy: { date: 'desc' },
select: {
accountId: true,
currency: true,
dataSource: true,
date: true,
fee: true,
quantity: true,
SymbolProfile: true,
type: true,
unitPrice: true
},
where: { userId }
});
return {
meta: { date: new Date().toISOString(), version: environment.version },
orders: orders.map(
({
accountId,
currency,
date,
fee,
quantity,
SymbolProfile,
type,
unitPrice
}) => {
return {
accountId,
currency,
date,
fee,
quantity,
type,
unitPrice,
dataSource: SymbolProfile.dataSource,
symbol: SymbolProfile.symbol
};
}
)
};
}
}