Skip to content

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

Bugfix/response of historical market data gathering for a specific date (#7717)

Thomas Kaul0d0ed972271e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9e51a5d09..2bc2148152 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Migrated the create and edit access dialogs to dedicated routes
+- Improved the response of the historical market data gathering endpoint for a specific date
### Fixed
diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts
index ade8781d6b..f47d216f4d 100644
--- a/apps/api/src/app/admin/admin.controller.ts
+++ b/apps/api/src/app/admin/admin.controller.ts
@@ -213,11 +213,20 @@ export class AdminController {
);
}
- return this.dataGatheringService.gatherSymbolForDate({
+ const marketData = await this.dataGatheringService.gatherSymbolForDate({
dataSource,
date,
symbol
});
+
+ if (!marketData) {
+ throw new HttpException(
+ getReasonPhrase(StatusCodes.NOT_FOUND),
+ StatusCodes.NOT_FOUND
+ );
+ }
+
+ return marketData;
}
@HasPermission(permissions.accessAdminControl)
diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts
index 51bf9ef6ae..7830d428e2 100644
--- a/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts
+++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts
@@ -219,5 +219,34 @@ describe('DataGatheringService', () => {
})
);
});
+
+ it('returns the upserted market data', async () => {
+ dataProviderService.getHistoricalRaw.mockResolvedValue({
+ 'YAHOO-AAPL': {
+ '2026-08-22': { marketPrice: 100 }
+ }
+ });
+ prismaService.marketData.upsert.mockResolvedValue({ marketPrice: 100 });
+
+ const marketData = await dataGatheringService.gatherSymbolForDate({
+ dataSource: 'YAHOO',
+ date: parseDate('2026-08-22'),
+ symbol: 'AAPL'
+ });
+
+ expect(marketData).toEqual({ marketPrice: 100 });
+ });
+
+ it('returns undefined if the data provider has no market price', async () => {
+ dataProviderService.getHistoricalRaw.mockResolvedValue({});
+
+ const marketData = await dataGatheringService.gatherSymbolForDate({
+ dataSource: 'YAHOO',
+ date: parseDate('2026-08-22'),
+ symbol: 'AAPL'
+ });
+
+ expect(marketData).toBeUndefined();
+ });
});
});
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 531f36f0dd..010fe5f90b 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
@@ -348,10 +348,10 @@ export class DataGatheringService {
});
}
} catch (error) {
- this.logger.error(error.message);
- } finally {
- return undefined;
+ this.logger.error(error?.message);
}
+
+ return undefined;
}
public async gatherSymbols({