From d60b9ad608cb89689423e4d9c8e55210e19a7802 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 5 Oct 2025 11:02:27 +0200 Subject: [PATCH] Add date range --- apps/api/src/app/admin/admin.controller.ts | 18 ++++++++++++++++-- .../data-gathering/data-gathering.service.ts | 14 +++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts index 27cc088d1..66f8483b4 100644 --- a/apps/api/src/app/admin/admin.controller.ts +++ b/apps/api/src/app/admin/admin.controller.ts @@ -6,6 +6,7 @@ import { ManualService } from '@ghostfolio/api/services/data-provider/manual/man import { DemoService } from '@ghostfolio/api/services/demo/demo.service'; import { PropertyDto } from '@ghostfolio/api/services/property/property.dto'; import { DataGatheringService } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.service'; +import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'; import { DATA_GATHERING_QUEUE_PRIORITY_HIGH, DATA_GATHERING_QUEUE_PRIORITY_MEDIUM, @@ -22,6 +23,7 @@ import { } from '@ghostfolio/common/interfaces'; import { permissions } from '@ghostfolio/common/permissions'; import type { + DateRange, MarketDataPreset, RequestWithUser } from '@ghostfolio/common/types'; @@ -161,9 +163,21 @@ export class AdminController { @HasPermission(permissions.accessAdminControl) public async gatherSymbol( @Param('dataSource') dataSource: DataSource, - @Param('symbol') symbol: string + @Param('symbol') symbol: string, + @Query('range') dateRange: DateRange ): Promise { - this.dataGatheringService.gatherSymbol({ dataSource, symbol }); + let date: Date; + + if (dateRange) { + const { startDate } = getIntervalFromDateRange(dateRange, new Date()); + date = startDate; + } + + this.dataGatheringService.gatherSymbol({ + dataSource, + date, + symbol + }); return; } diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts index 31edf6ffc..dd93e3e47 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts @@ -94,17 +94,21 @@ export class DataGatheringService { }); } - public async gatherSymbol({ dataSource, symbol }: AssetProfileIdentifier) { + public async gatherSymbol({ dataSource, date, symbol }: IDataGatheringItem) { await this.marketDataService.deleteMany({ dataSource, symbol }); - const dataGatheringItems = (await this.getSymbolsMax()).filter( - (dataGatheringItem) => { + const dataGatheringItems = (await this.getSymbolsMax()) + .filter((dataGatheringItem) => { return ( dataGatheringItem.dataSource === dataSource && dataGatheringItem.symbol === symbol ); - } - ); + }) + .map((item) => ({ + ...item, + date: date ?? item.date + })); + await this.gatherSymbols({ dataGatheringItems, priority: DATA_GATHERING_QUEUE_PRIORITY_HIGH