<commit_before>const Errors = require('common-errors');
const is = require('is');
const moduleLifecycle = require('./lifecycle');
const Promise = require('bluebird');

function validate(request) {
  const validator = this.validator;

  return validator.validate(request.action.schema, request.params)
    .tap((sanitizedParams) => {
      request.params = sanitizedParams;
    })
    .return(request)
    .catch((error) => {
      if (error.constructor === Errors.ValidationError) {
        throw error;
      }

      throw new Errors.Error(error);
    });
}

function validateHandler(request) {
  if (request.action === undefined) {
    return Promise.reject(new Errors.ArgumentError('"request" must have property "action"'));
  }

  if (is.undefined(request.action.schema) === true) {
    return Promise.resolve(request);
  }
<commit_msg>fix: correctly validate query instead of payload on get request<commit_after>const Errors = require('common-errors');
const is = require('is');
const moduleLifecycle = require('./lifecycle');
const Promise = require('bluebird');
const { ActionTransport } = require('../../..');

// based on this we validate input data
const DATA_KEY_SELECTOR = {
  get: 'query',
  post: 'params',
  [ActionTransport.amqp]: 'params',
  [ActionTransport.socketIO]: 'params',
};

function validate(request) {
  const validator = this.validator;
  const paramsKey = DATA_KEY_SELECTOR[request.method];

  return validator
    .validate(request.action.schema, request[paramsKey])
    .then((sanitizedParams) => {
      request[paramsKey] = sanitizedParams;
      return request;
    })
    .catch((error) => {
      if (error.constructor === Errors.ValidationError) {
        throw error;
      }

      throw new Errors.Error(error);
    });
}

function validateHandler(request) {
  if (request.action === undefined) {
    return Promise.reject(new Errors.ArgumentError('"request" must have property "action"'));
  }

  if (is.undefined(request.action.schema) === true) {
    return Promise.resolve(request);
  }

{'fraction_non_alphanumeric': 0.1455976389572061, 'fraction_numerical': 0.0, 'mean_word_length': 3.889423076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '116133', 'n_tokens_mistral': 592, 'n_tokens_neox': 584, 'n_words': 134}