import { Injectable } from '@nestjs/common'; import { HealthCheckError, HealthIndicator, HealthIndicatorResult, } from '@nestjs/terminus'; import { ICheckRepository } from '../interfaces/check-repository.interface'; import { AdRepository } from '../../../ad/adapters/secondaries/ad.repository'; @Injectable() export class RepositoriesHealthIndicatorUseCase extends HealthIndicator { private checkRepositories: ICheckRepository[]; constructor(private readonly adRepository: AdRepository) { super(); this.checkRepositories = [adRepository]; } isHealthy = async (key: string): Promise => { try { await Promise.all( this.checkRepositories.map( async (checkRepository: ICheckRepository) => { await checkRepository.healthCheck(); }, ), ); return this.getStatus(key, true); } catch (e: any) { throw new HealthCheckError('Repository', { repository: e.message, }); } }; }