Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/add date range query parameter to data gathering endpoint (#5684)

Thomas Kaul180e0f3c817d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5583fd59d9..fecc9758e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Added
+
+- Added support for a date range query parameter in the data gathering endpoint
+
## 2.206.0 - 2025-10-04
### Changed
diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts
index 27cc088d17..66f8483b40 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<void> {
- 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 31edf6ffca..dd93e3e478 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