mirror of https://github.com/ghostfolio/ghostfolio
Thomas
4 years ago
committed by
GitHub
14 changed files with 164 additions and 5 deletions
@ -0,0 +1,23 @@ |
|||||
|
import { Export } from '@ghostfolio/common/interfaces'; |
||||
|
import { RequestWithUser } from '@ghostfolio/common/types'; |
||||
|
import { Controller, Get, Inject, UseGuards } from '@nestjs/common'; |
||||
|
import { REQUEST } from '@nestjs/core'; |
||||
|
import { AuthGuard } from '@nestjs/passport'; |
||||
|
|
||||
|
import { ExportService } from './export.service'; |
||||
|
|
||||
|
@Controller('export') |
||||
|
export class ExportController { |
||||
|
public constructor( |
||||
|
private readonly exportService: ExportService, |
||||
|
@Inject(REQUEST) private readonly request: RequestWithUser |
||||
|
) {} |
||||
|
|
||||
|
@Get() |
||||
|
@UseGuards(AuthGuard('jwt')) |
||||
|
public async export(): Promise<Export> { |
||||
|
return await this.exportService.export({ |
||||
|
userId: this.request.user.id |
||||
|
}); |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; |
||||
|
import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; |
||||
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; |
||||
|
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; |
||||
|
import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; |
||||
|
import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; |
||||
|
import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; |
||||
|
import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; |
||||
|
import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; |
||||
|
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; |
||||
|
import { Module } from '@nestjs/common'; |
||||
|
|
||||
|
import { ExportController } from './export.controller'; |
||||
|
import { ExportService } from './export.service'; |
||||
|
|
||||
|
@Module({ |
||||
|
imports: [RedisCacheModule], |
||||
|
controllers: [ExportController], |
||||
|
providers: [ |
||||
|
AlphaVantageService, |
||||
|
CacheService, |
||||
|
ConfigurationService, |
||||
|
DataGatheringService, |
||||
|
DataProviderService, |
||||
|
ExportService, |
||||
|
GhostfolioScraperApiService, |
||||
|
PrismaService, |
||||
|
RakutenRapidApiService, |
||||
|
YahooFinanceService |
||||
|
] |
||||
|
}) |
||||
|
export class ExportModule {} |
@ -0,0 +1,31 @@ |
|||||
|
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 { |
||||
|
public constructor(private prisma: PrismaService) {} |
||||
|
|
||||
|
public async export({ userId }: { userId: string }): Promise<Export> { |
||||
|
const orders = await this.prisma.order.findMany({ |
||||
|
orderBy: { date: 'desc' }, |
||||
|
select: { |
||||
|
currency: true, |
||||
|
dataSource: true, |
||||
|
date: true, |
||||
|
fee: true, |
||||
|
quantity: true, |
||||
|
symbol: true, |
||||
|
type: true, |
||||
|
unitPrice: true |
||||
|
}, |
||||
|
where: { userId } |
||||
|
}); |
||||
|
|
||||
|
return { |
||||
|
meta: { date: new Date().toISOString(), version: environment.version }, |
||||
|
orders |
||||
|
}; |
||||
|
} |
||||
|
} |
@ -1,3 +1,4 @@ |
|||||
export const environment = { |
export const environment = { |
||||
production: true |
production: true, |
||||
|
version: `v${require('../../../../package.json').version}` |
||||
}; |
}; |
||||
|
@ -1,3 +1,4 @@ |
|||||
export const environment = { |
export const environment = { |
||||
production: false |
production: false, |
||||
|
version: 'dev' |
||||
}; |
}; |
||||
|
@ -0,0 +1,9 @@ |
|||||
|
import { Order } from '@prisma/client'; |
||||
|
|
||||
|
export interface Export { |
||||
|
meta: { |
||||
|
date: string; |
||||
|
version: string; |
||||
|
}; |
||||
|
orders: Partial<Order>[]; |
||||
|
} |
Loading…
Reference in new issue