import {
  CanActivate,
  ExecutionContext,
  Injectable,
  UnsupportedMediaTypeException,
} from '@nestjs/common';
import { Request } from 'express';

@Injectable()
export class MultipartFormDataGuard implements CanActivate {
  canActivate(context: ExecutionContext): boolean {
    const request = context.switchToHttp().getRequest<Request>();

    if (request.is('multipart/form-data')) {
      return true;
    }

    throw new UnsupportedMediaTypeException('Content-Type must be multipart/form-data');
  }
}
