Skip to content

Commit

Permalink
refactor(mikroorm): get mikroorm instance with class
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Jun 26, 2022
1 parent 56e250d commit a2a50a1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/health-indicator/database/mikro-orm.health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, NotImplementedException, Scope } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { HealthCheckError } from '../../health-check/health-check.error';

import type { Connection } from '@mikro-orm/core';
import * as MikroOrmNestJS from '@mikro-orm/core';
import { TimeoutError } from '../../errors';
import {
TimeoutError as PromiseTimeoutError,
Expand Down Expand Up @@ -100,10 +100,12 @@ export class MikroOrmHealthIndicator extends HealthIndicator {
/**
* Returns the connection of the current DI context
*/
private getContextConnection(): Connection | null {
const mikro = this.moduleRef.get('MikroORM', { strict: false });
private getContextConnection(): MikroOrmNestJS.Connection | null {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { MikroORM } = require('@mikro-orm/nestjs') as typeof MikroOrmNestJS;
const mikro = this.moduleRef.get(MikroORM, { strict: false });

const connection: Connection = mikro.em.getConnection();
const connection: MikroOrmNestJS.Connection = mikro.em.getConnection();

if (!connection) {
return null;
Expand All @@ -118,7 +120,7 @@ export class MikroOrmHealthIndicator extends HealthIndicator {
* @param timeout The timeout how long the ping should maximum take
*
*/
private async pingDb(connection: Connection, timeout: number) {
private async pingDb(connection: MikroOrmNestJS.Connection, timeout: number) {
let check: Promise<any>;
const type = connection.getPlatform().getConfig().get('type');

Expand Down

0 comments on commit a2a50a1

Please sign in to comment.