{"size": 1522, "ext": "js", "max_stars_repo_path": "services/aws/index.js", "max_stars_repo_name": "joseph-mccombs/puente-reactnative-collect", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "services/aws/index.js", "max_issues_repo_name": "joseph-mccombs/puente-reactnative-collect", "max_issues_repo_issues_event_min_datetime": "2020-07-05T21:46:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:55:43.000Z", "max_forks_repo_path": "services/aws/index.js", "max_forks_repo_name": "jamccomb92/puente-reactnative-collect", "max_forks_repo_forks_event_min_datetime": "2020-06-18T20:58:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-02T21:16:56.000Z"}
{"max_stars_count": null, "max_issues_count": 168, "max_forks_count": 6, "avg_line_length": 30.44, "max_line_length": 92, "alphanum_fraction": 0.5827858081}
import selectedENV from '../../environment';

const axios = require('axios');

function retrievePuenteAutofillData(parameter) {
  const { AWS_LAMBDA_URL } = selectedENV;
  return axios.get(AWS_LAMBDA_URL, {
    params: {
      bucket_name: 'google-sheets-lambda',
      key: 'test/puente-test.json',
      parameter: 'all'
    }
  })
    .then((response) => {
      if (parameter !== 'all') {
        const results = [];
        const resultsCapitalized = [];
        response.data.forEach((object) => {
          const objectCapitilized = object[parameter].toUpperCase().trim();
          if (!resultsCapitalized.includes(objectCapitilized) && object[parameter] !== '') {
            resultsCapitalized.push(objectCapitilized);
            results.push(object[parameter]);
          }
        });
        return results;
      }

      const keys = Object.keys(response.data[0]);
      const allData = {};
      keys.forEach((key) => {
        const results = [];
        const resultsCapitalized = [];
        response.data.forEach((object) => {
          const objectCapitilized = object[key].toUpperCase().trim();
          if (!resultsCapitalized.includes(objectCapitilized) && object[key] !== '') {
            resultsCapitalized.push(objectCapitilized);
            results.push(object[key]);
          }
        });
        allData[key] = results;
      });
      return allData;
    })
    .catch((error) => {
      console.log(error); // eslint-disable-line
    });
}

export default retrievePuenteAutofillData;
