|
|
@ -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) }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|