diff --git a/CHANGELOG.md b/CHANGELOG.md index d9e51a5d0..2bc214815 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 ade8781d6..f47d216f4 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 51bf9ef6a..7830d428e 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 531f36f0d..010fe5f90 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({