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.
75 lines
2.2 KiB
75 lines
2.2 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 { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.interceptor';
|
|
import { ApiService } from '@ghostfolio/api/services/api/api.service';
|
|
import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper';
|
|
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';
|
|
import { GetExportDto } from './get-export.dto';
|
|
|
|
@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)
|
|
@UseInterceptors(TransformDataSourceInResponseInterceptor)
|
|
public async export(
|
|
@Query()
|
|
{
|
|
accounts,
|
|
activityIds,
|
|
activityTypes,
|
|
assetClasses,
|
|
dataSource,
|
|
range,
|
|
symbol,
|
|
tags
|
|
}: GetExportDto
|
|
): Promise<ExportResponse> {
|
|
let endDate: Date;
|
|
let startDate: Date;
|
|
|
|
if (range) {
|
|
({ endDate, startDate } = getIntervalFromDateRange({
|
|
dateRange: range
|
|
}));
|
|
}
|
|
|
|
const filters = this.apiService.buildFiltersFromQueryParams({
|
|
filterByAccounts: accounts,
|
|
filterByAssetClasses: assetClasses,
|
|
filterByDataSource: dataSource,
|
|
filterBySymbol: symbol,
|
|
filterByTags: tags
|
|
});
|
|
|
|
return this.exportService.export({
|
|
activityIds,
|
|
activityTypes,
|
|
endDate,
|
|
filters,
|
|
startDate,
|
|
userId: this.request.user.id,
|
|
userSettings: this.request.user.settings.settings
|
|
});
|
|
}
|
|
}
|
|
|