Vizzuality/landgriffon

View on GitHub
api/src/modules/import-data/xlsx-payload.interceptor.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import {
  BadRequestException,
  CallHandler,
  ExecutionContext,
  Injectable,
  NestInterceptor,
} from '@nestjs/common';
import { Request } from 'express';

@Injectable()
export class XlsxPayloadInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): any {
    const request: Request = context.switchToHttp().getRequest<Request>();
    if (!request?.file) {
      throw new BadRequestException(`A .XLSX file must be provided as payload`);
    }

    return next.handle();
  }
}