text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.ValidationPipe = void 0;
  const common_1 = require("@nestjs/common");
  const class_transformer_1 = require("class-transformer");
  const class_validator_1 = require("class-validator");
  class ValidationPipe {
      async transform(value, { metatype }) {
          if (!metatype || !this.toValidate(metatype)) {
              return value;
          }
          const object = (0, class_transformer_1.plainToClass)(metatype, value);
          const errors = await (0, class_validator_1.validate)(object);
          if (errors.length > 0) {
              throw new common_1.BadRequestException('Validation failed');
          }
          return value;
      }
      toValidate(metatype) {
          const types = [String, Boolean, Number, Array, Object];
          return !types.includes(metatype);
      }
  }
  exports.ValidationPipe = ValidationPipe;
  //# sourceMappingURL=validation.pipe.js.map