Browse Source

Add query params

pull/4311/head
Thomas Kaul 6 months ago
parent
commit
a14388c09f
  1. 22
      apps/api/src/app/benchmark/benchmark.controller.ts
  2. 2
      apps/api/src/app/benchmark/benchmark.module.ts
  3. 13
      apps/api/src/app/benchmark/benchmark.service.ts
  4. 1
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts
  5. 12
      apps/client/src/app/services/data.service.ts

22
apps/api/src/app/benchmark/benchmark.controller.ts

@ -2,6 +2,7 @@ import { HasPermission } from '@ghostfolio/api/decorators/has-permission.decorat
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 { HEADER_KEY_IMPERSONATION } from '@ghostfolio/common/config';
import type {
@ -36,6 +37,7 @@ import { BenchmarkService } from './benchmark.service';
@Controller('benchmark')
export class BenchmarkController {
public constructor(
private readonly apiService: ApiService,
private readonly benchmarkService: BenchmarkService,
@Inject(REQUEST) private readonly request: RequestWithUser
) {}
@ -114,20 +116,38 @@ export class BenchmarkController {
@Param('dataSource') dataSource: DataSource,
@Param('startDateString') startDateString: string,
@Param('symbol') symbol: string,
@Query('range') dateRange: DateRange = 'max'
@Query('range') dateRange: DateRange = 'max',
@Query('accounts') filterByAccounts?: string,
@Query('assetClasses') filterByAssetClasses?: string,
@Query('dataSource') filterByDataSource?: string,
@Query('symbol') filterBySymbol?: string,
@Query('tags') filterByTags?: string,
@Query('withExcludedAccounts') withExcludedAccountsParam = 'false'
): Promise<BenchmarkMarketDataDetails> {
const { endDate, startDate } = getIntervalFromDateRange(
dateRange,
new Date(startDateString)
);
const filters = this.apiService.buildFiltersFromQueryParams({
filterByAccounts,
filterByAssetClasses,
filterByDataSource,
filterBySymbol,
filterByTags
});
const withExcludedAccounts = withExcludedAccountsParam === 'true';
return this.benchmarkService.getMarketDataForUser({
dataSource,
dateRange,
endDate,
filters,
impersonationId,
startDate,
symbol,
withExcludedAccounts,
user: this.request.user
});
}

2
apps/api/src/app/benchmark/benchmark.module.ts

@ -10,6 +10,7 @@ import { SymbolModule } from '@ghostfolio/api/app/symbol/symbol.module';
import { UserModule } from '@ghostfolio/api/app/user/user.module';
import { TransformDataSourceInRequestModule } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.module';
import { TransformDataSourceInResponseModule } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.module';
import { ApiModule } from '@ghostfolio/api/services/api/api.module';
import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module';
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module';
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.module';
@ -30,6 +31,7 @@ import { BenchmarkService } from './benchmark.service';
controllers: [BenchmarkController],
exports: [BenchmarkService],
imports: [
ApiModule,
ConfigurationModule,
DataProviderModule,
ExchangeRateDataModule,

13
apps/api/src/app/benchmark/benchmark.service.ts

@ -22,7 +22,8 @@ import {
Benchmark,
BenchmarkMarketDataDetails,
BenchmarkProperty,
BenchmarkResponse
BenchmarkResponse,
Filter
} from '@ghostfolio/common/interfaces';
import {
BenchmarkTrend,
@ -156,16 +157,20 @@ export class BenchmarkService {
dataSource,
dateRange,
endDate = new Date(),
filters,
impersonationId,
startDate,
symbol,
user
user,
withExcludedAccounts
}: {
dateRange: DateRange;
endDate?: Date;
filters?: Filter[];
impersonationId: string;
startDate: Date;
user: UserWithSettings;
withExcludedAccounts?: boolean;
} & AssetProfileIdentifier): Promise<BenchmarkMarketDataDetails> {
const marketData: { date: string; value: number }[] = [];
const userCurrency = user.Settings.settings.baseCurrency;
@ -173,8 +178,10 @@ export class BenchmarkService {
const { chart } = await this.portfolioService.getPerformance({
dateRange,
filters,
impersonationId,
userId
userId,
withExcludedAccounts
});
const [currentSymbolItem, marketDataItems] = await Promise.all([

1
apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

@ -321,6 +321,7 @@ export class AnalysisPageComponent implements OnDestroy, OnInit {
.fetchBenchmarkForUser({
dataSource,
symbol,
filters: this.userService.getFilters(),
range: this.user?.settings?.dateRange,
startDate: this.firstOrderDate
})

12
apps/client/src/app/services/data.service.ts

@ -338,17 +338,23 @@ export class DataService {
public fetchBenchmarkForUser({
dataSource,
filters,
range,
startDate,
symbol
symbol,
withExcludedAccounts
}: {
filters?: Filter[];
range: DateRange;
startDate: Date;
withExcludedAccounts?: boolean;
} & AssetProfileIdentifier): Observable<BenchmarkMarketDataDetails> {
let params = new HttpParams();
let params = this.buildFiltersAsQueryParams({ filters });
if (range) {
params = params.append('range', range);
if (withExcludedAccounts) {
params = params.append('withExcludedAccounts', withExcludedAccounts);
}
return this.http.get<BenchmarkMarketDataDetails>(

Loading…
Cancel
Save