import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; import { AppLogger } from '../../logger'; import { TypeOrmConnectionManagerService } from '../../database'; @Injectable() export class ConnectionManagerGuard implements CanActivate { private readonly TAG: string = `${this.constructor.name}`; constructor() { AppLogger.log('Init', this.TAG); } async canActivate(context: ExecutionContext): Promise { try { if (TypeOrmConnectionManagerService.isConnection) { AppLogger.debug('Reconnecting driver to the DB are in progress', this.TAG); await TypeOrmConnectionManagerService.reconnectionPromise; } } catch (e) { AppLogger.error(e, this.TAG); } return true; } }