All files / core application-config.ts

100% Statements 23/23
100% Branches 1/1
100% Functions 17/17
100% Lines 23/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                  1x 72x 72x 72x 72x 72x   72x     1x       3x       1x       1x       2x       1x       15x       2x       1x       8x       4x       2x       1x       4x       2x       1x      
import {
  PipeTransform,
  WebSocketAdapter,
  ExceptionFilter,
  NestInterceptor,
  CanActivate,
} from '@nestjs/common';
import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface';
 
export class ApplicationConfig implements ConfigurationProvider {
  private globalPipes: PipeTransform<any>[] = [];
  private globalFilters: ExceptionFilter[] = [];
  private globalInterceptors: NestInterceptor[] = [];
  private globalGuards: CanActivate[] = [];
  private globalPrefix = '';
 
  constructor(private ioAdapter: WebSocketAdapter | null = null) {}
 
  public setGlobalPrefix(prefix: string) {
    this.globalPrefix = prefix;
  }
 
  public getGlobalPrefix() {
    return this.globalPrefix;
  }
 
  public setIoAdapter(ioAdapter: WebSocketAdapter) {
    this.ioAdapter = ioAdapter;
  }
 
  public getIoAdapter(): WebSocketAdapter {
    return this.ioAdapter;
  }
 
  public addGlobalPipe(pipe: PipeTransform<any>) {
    this.globalPipes.push(pipe);
  }
 
  public useGlobalPipes(...pipes: PipeTransform<any>[]) {
    this.globalPipes = this.globalPipes.concat(pipes);
  }
 
  public getGlobalFilters(): ExceptionFilter[] {
    return this.globalFilters;
  }
 
  public addGlobalFilter(filter: ExceptionFilter) {
    this.globalFilters.push(filter);
  }
 
  public useGlobalFilters(...filters: ExceptionFilter[]) {
    this.globalFilters = this.globalFilters.concat(filters);
  }
 
  public getGlobalPipes(): PipeTransform<any>[] {
    return this.globalPipes;
  }
 
  public getGlobalInterceptors(): NestInterceptor[] {
    return this.globalInterceptors;
  }
 
  public addGlobalInterceptor(interceptor: NestInterceptor) {
    this.globalInterceptors.push(interceptor);
  }
 
  public useGlobalInterceptors(...interceptors: NestInterceptor[]) {
    this.globalInterceptors = this.globalInterceptors.concat(interceptors);
  }
 
  public getGlobalGuards(): CanActivate[] {
    return this.globalGuards;
  }
 
  public addGlobalGuard(guard: CanActivate) {
    this.globalGuards.push(guard);
  }
 
  public useGlobalGuards(...guards: CanActivate[]) {
    this.globalGuards = this.globalGuards.concat(guards);
  }
}