mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard';
|
|
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor';
|
|
import { ApiService } from '@ghostfolio/api/services/api/api.service';
|
|
import { ExportResponse } from '@ghostfolio/common/interfaces';
|
|
import type { RequestWithUser } from '@ghostfolio/common/types';
|
|
|
|
import {
|
|
Controller,
|
|
Get,
|
|
Inject,
|
|
Query,
|
|
UseGuards,
|
|
UseInterceptors
|
|
} 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 apiService: ApiService,
|
|
private readonly exportService: ExportService,
|
|
@Inject(REQUEST) private readonly request: RequestWithUser
|
|
) {}
|
|
|
|
@Get()
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor)
|
|
public async export(
|
|
@Query('accounts') filterByAccounts?: string,
|
|
@Query('activityIds') filterByActivityIds?: string,
|
|
@Query('assetClasses') filterByAssetClasses?: string,
|
|
@Query('dataSource') filterByDataSource?: string,
|
|
@Query('symbol') filterBySymbol?: string,
|
|
@Query('tags') filterByTags?: string
|
|
): Promise<ExportResponse> {
|
|
const activityIds = filterByActivityIds?.split(',') ?? [];
|
|
const filters = this.apiService.buildFiltersFromQueryParams({
|
|
filterByAccounts,
|
|
filterByAssetClasses,
|
|
filterByDataSource,
|
|
filterBySymbol,
|
|
filterByTags
|
|
});
|
|
|
|
return this.exportService.export({
|
|
activityIds,
|
|
filters,
|
|
userId: this.request.user.id,
|
|
userSettings: this.request.user.settings.settings
|
|
});
|
|
}
|
|
}
|
|
|