All files xapi-request-interceptor.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 2/2
100% Lines 13/13

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 171x       1x 1x 4x 1x 3x 3x   3x 1x 1x 3x 3x 1x
import { CallHandler, ExecutionContext, Injectable, Logger, NestInterceptor } from "@nestjs/common";
import { parse } from "@xapi-js/core";
import { Observable } from "rxjs";
 
@Injectable()
export class XapiRequestInterceptor implements NestInterceptor {
  private readonly logger: Logger = new Logger(XapiRequestInterceptor.name);
  async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>> {
    const request = context.switchToHttp().getRequest();
    this.logger.debug(`XapiRequestInterceptor Intercepting request: ${request.method} ${request.url}`);
    // Deserialize XML input to XapiRoot object
    if (request.headers['content-type'] === 'application/xml' && request.body) {
      request.body = await parse(request.body);
    }
    return next.handle()
  }
}