Browse Source

Fix response of historical market data gathering for a specific date

pull/7717/head
Thomas Kaul 5 days ago
parent
commit
87eef996f4
  1. 11
      apps/api/src/app/admin/admin.controller.ts
  2. 29
      apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts
  3. 4
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts

11
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, dataSource,
date, date,
symbol symbol
}); });
if (!marketData) {
throw new HttpException(
getReasonPhrase(StatusCodes.NOT_FOUND),
StatusCodes.NOT_FOUND
);
}
return marketData;
} }
@HasPermission(permissions.accessAdminControl) @HasPermission(permissions.accessAdminControl)

29
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();
});
}); });
}); });

4
apps/api/src/services/queues/data-gathering/data-gathering.service.ts

@ -349,9 +349,9 @@ export class DataGatheringService {
} }
} catch (error) { } catch (error) {
this.logger.error(error.message); this.logger.error(error.message);
} finally {
return undefined;
} }
return undefined;
} }
public async gatherSymbols({ public async gatherSymbols({

Loading…
Cancel
Save