Skip to content

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

Feature/refactor health check endpoints (#5005)

Thomas Kaulbe3a9b8e83e9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 275871fd9e..d87d850dc1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Migrated the `@ghostfolio/ui/value` component to control flow
+- Refactored the health check endpoint for data enhancers
+- Refactored the health check endpoint for data providers
## 2.173.0 - 2025-06-21
diff --git a/apps/api/src/app/health/health.controller.ts b/apps/api/src/app/health/health.controller.ts
index 6ff09825b4..5542ae9333 100644
--- a/apps/api/src/app/health/health.controller.ts
+++ b/apps/api/src/app/health/health.controller.ts
@@ -1,4 +1,8 @@
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor';
+import {
+ DataEnhancerHealthResponse,
+ DataProviderHealthResponse
+} from '@ghostfolio/common/interfaces';
import {
Controller,
@@ -37,23 +41,30 @@ export class HealthController {
}
@Get('data-enhancer/:name')
- public async getHealthOfDataEnhancer(@Param('name') name: string) {
+ public async getHealthOfDataEnhancer(
+ @Param('name') name: string,
+ @Res() response: Response
+ ): Promise<Response<DataEnhancerHealthResponse>> {
const hasResponse =
await this.healthService.hasResponseFromDataEnhancer(name);
- if (hasResponse !== true) {
- throw new HttpException(
- getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE),
- StatusCodes.SERVICE_UNAVAILABLE
- );
+ if (hasResponse) {
+ return response.status(HttpStatus.OK).json({
+ status: getReasonPhrase(StatusCodes.OK)
+ });
+ } else {
+ return response
+ .status(HttpStatus.SERVICE_UNAVAILABLE)
+ .json({ status: getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE) });
}
}
@Get('data-provider/:dataSource')
@UseInterceptors(TransformDataSourceInRequestInterceptor)
public async getHealthOfDataProvider(
- @Param('dataSource') dataSource: DataSource
- ) {
+ @Param('dataSource') dataSource: DataSource,
+ @Res() response: Response
+ ): Promise<Response<DataProviderHealthResponse>> {
if (!DataSource[dataSource]) {
throw new HttpException(
getReasonPhrase(StatusCodes.NOT_FOUND),
@@ -64,11 +75,14 @@ export class HealthController {
const hasResponse =
await this.healthService.hasResponseFromDataProvider(dataSource);
- if (hasResponse !== true) {
- throw new HttpException(
- getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE),
- StatusCodes.SERVICE_UNAVAILABLE
- );
+ if (hasResponse) {
+ return response
+ .status(HttpStatus.OK)
+ .json({ status: getReasonPhrase(StatusCodes.OK) });
+ } else {
+ return response
+ .status(HttpStatus.SERVICE_UNAVAILABLE)
+ .json({ status: getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE) });
}
}
}
diff --git a/libs/common/src/lib/interfaces/index.ts b/libs/common/src/lib/interfaces/index.ts
index e401705fbe..e7a0e7f760 100644
--- a/libs/common/src/lib/interfaces/index.ts
+++ b/libs/common/src/lib/interfaces/index.ts
@@ -41,8 +41,10 @@ import type { AccountsResponse } from './responses/accounts-response.interface';
import type { AiPromptResponse } from './responses/ai-prompt-response.interface';
import type { ApiKeyResponse } from './responses/api-key-response.interface';
import type { BenchmarkResponse } from './responses/benchmark-response.interface';
+import type { DataEnhancerHealthResponse } from './responses/data-enhancer-health-response.interface';
import type { DataProviderGhostfolioAssetProfileResponse } from './responses/data-provider-ghostfolio-asset-profile-response.interface';
import type { DataProviderGhostfolioStatusResponse } from './responses/data-provider-ghostfolio-status-response.interface';
+import type { DataProviderHealthResponse } from './responses/data-provider-health-response.interface';
import type { DividendsResponse } from './responses/dividends-response.interface';
import type { ResponseError } from './responses/errors.interface';
import type { HistoricalResponse } from './responses/historical-response.interface';
@@ -88,8 +90,10 @@ export {
BenchmarkProperty,
BenchmarkResponse,
Coupon,
+ DataEnhancerHealthResponse,
DataProviderGhostfolioAssetProfileResponse,
DataProviderGhostfolioStatusResponse,
+ DataProviderHealthResponse,
DataProviderInfo,
DividendsResponse,
EnhancedSymbolProfile,
diff --git a/libs/common/src/lib/interfaces/responses/data-enhancer-health-response.interface.ts b/libs/common/src/lib/interfaces/responses/data-enhancer-health-response.interface.ts
new file mode 100644
index 0000000000..025f8e8be9
--- /dev/null
+++ b/libs/common/src/lib/interfaces/responses/data-enhancer-health-response.interface.ts
@@ -0,0 +1,3 @@
+export interface DataEnhancerHealthResponse {
+ status: string;
+}
diff --git a/libs/common/src/lib/interfaces/responses/data-provider-health-response.interface.ts b/libs/common/src/lib/interfaces/responses/data-provider-health-response.interface.ts
new file mode 100644
index 0000000000..a32d9b3c3c
--- /dev/null
+++ b/libs/common/src/lib/interfaces/responses/data-provider-health-response.interface.ts
@@ -0,0 +1,3 @@
+export interface DataProviderHealthResponse {
+ status: string;
+}