All files / src/modules/health prisma.health.ts

66.66% Statements 8/12
60% Branches 3/5
50% Functions 1/2
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1911x 11x 11x     11x 11x 11x                      
import { Injectable } from '@nestjs/common';
import { HealthCheckError, HealthIndicator, HealthIndicatorResult } from '@nestjs/terminus';
import { PrismaService } from '@app/modules/prisma/prisma.service';
 
@Injectable()
export class PrismaHealthIndicatorService extends HealthIndicator {
  constructor(private readonly prisma: PrismaService) {
    super();
  }
 
  async isHealthy(key = 'prisma'): Promise<HealthIndicatorResult> {
    try {
      await this.prisma.client.$queryRaw`SELECT 1`;
      return this.getStatus(key, true);
    } catch (_error) {
      throw new HealthCheckError('Prisma ping failed', this.getStatus(key, false));
    }
  }
}