{"size": 1203, "ext": "js", "max_stars_repo_path": "src/helpers/requestHelpers.js", "max_stars_repo_name": "diegosantos-dev/salesSystem", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/helpers/requestHelpers.js", "max_issues_repo_name": "diegosantos-dev/salesSystem", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/helpers/requestHelpers.js", "max_forks_repo_name": "diegosantos-dev/salesSystem", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.6981132075, "max_line_length": 63, "alphanum_fraction": 0.5295095594}
/* eslint-disable object-curly-newline */
import API from 'utils/API';

const defineEndpoint = (endPoint, id, query) => {
  if (typeof endPoint === 'function') {
    return endPoint(id);
  }
  if (query) {
    return `${endPoint}${query}`;
  }
  if (id) {
    return `${endPoint}/${id}`;
  }
  return endPoint;
};

const requestAPI = ({ verb, endPoint, data, id, query }) => {
  Object.assign(API.defaults, {
    headers: {},
  });

  switch (verb) {
    case 'GET':
      return API.get(defineEndpoint(endPoint, id, query), data)
        .then((res) => res.data)
        .catch((error) => {
          throw error;
        });
    case 'POST':
      return API.post(defineEndpoint(endPoint, id), data)
        .then((res) => res.data)
        .catch((error) => {
          throw error;
        });
    case 'PUT':
      return API.put(defineEndpoint(endPoint, id), data)
        .then((res) => res.data)
        .catch((error) => {
          throw error;
        });
    case 'DELETE':
      return API.delete(defineEndpoint(endPoint, id))
        .then((res) => res.data)
        .catch((error) => {
          throw error;
        });
    default:
      return null;
  }
};

export default requestAPI;
