mirror of https://github.com/ghostfolio/ghostfolio
13 changed files with 123 additions and 1 deletions
@ -0,0 +1,44 @@ |
|||||
|
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor'; |
||||
|
import { |
||||
|
Controller, |
||||
|
Get, |
||||
|
HttpException, |
||||
|
Param, |
||||
|
UseInterceptors |
||||
|
} from '@nestjs/common'; |
||||
|
|
||||
|
import { HealthService } from './health.service'; |
||||
|
import { DataSource } from '@prisma/client'; |
||||
|
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
||||
|
|
||||
|
@Controller('health') |
||||
|
export class HealthController { |
||||
|
public constructor(private readonly healthService: HealthService) {} |
||||
|
|
||||
|
@Get() |
||||
|
public async getHealth() {} |
||||
|
|
||||
|
@Get('data-provider/:dataSource') |
||||
|
@UseInterceptors(TransformDataSourceInRequestInterceptor) |
||||
|
public async getHealthOfDataProvider( |
||||
|
@Param('dataSource') dataSource: DataSource |
||||
|
) { |
||||
|
if (!DataSource[dataSource]) { |
||||
|
throw new HttpException( |
||||
|
getReasonPhrase(StatusCodes.NOT_FOUND), |
||||
|
StatusCodes.NOT_FOUND |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
const hasResponse = await this.healthService.hasResponseFromDataProvider( |
||||
|
dataSource |
||||
|
); |
||||
|
|
||||
|
if (hasResponse !== true) { |
||||
|
throw new HttpException( |
||||
|
getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE), |
||||
|
StatusCodes.SERVICE_UNAVAILABLE |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; |
||||
|
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; |
||||
|
import { Module } from '@nestjs/common'; |
||||
|
|
||||
|
import { HealthController } from './health.controller'; |
||||
|
import { HealthService } from './health.service'; |
||||
|
|
||||
|
@Module({ |
||||
|
controllers: [HealthController], |
||||
|
imports: [ConfigurationModule, DataProviderModule], |
||||
|
providers: [HealthService] |
||||
|
}) |
||||
|
export class HealthModule {} |
@ -0,0 +1,14 @@ |
|||||
|
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; |
||||
|
import { Injectable } from '@nestjs/common'; |
||||
|
import { DataSource } from '@prisma/client'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class HealthService { |
||||
|
public constructor( |
||||
|
private readonly dataProviderService: DataProviderService |
||||
|
) {} |
||||
|
|
||||
|
public async hasResponseFromDataProvider(aDataSource: DataSource) { |
||||
|
return this.dataProviderService.checkQuote(aDataSource); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue