{"size": 748, "ext": "js", "max_stars_repo_path": "src/utils/api/updateEntry.js", "max_stars_repo_name": "Azerii/cityshoppa-admin", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/utils/api/updateEntry.js", "max_issues_repo_name": "Azerii/cityshoppa-admin", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/api/updateEntry.js", "max_forks_repo_name": "Azerii/cityshoppa-admin", "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": 23.375, "max_line_length": 74, "alphanum_fraction": 0.5842245989}
import axios from 'axios';
import { API_HOST } from '../config';
// import getCollection from './getCollection';
import getToken from './getToken';

const updateEntry = async (collectionType, data, id) => {
  const token = getToken();
  try {
    let res;
    if (id) {
      res = await axios.put(`${API_HOST}/${collectionType}/${id}`, data, {
        headers: { Authorization: `Bearer ${token}` }
      });
    } else {
      res = await axios.put(`${API_HOST}/${collectionType}`, data, {
        headers: { Authorization: `Bearer ${token}` }
      });
    }

    if (res.data.id) {
      // await getCollection(collectionType);
      return res.data;
    }
  } catch (e) {
    console.log(e);
  }

  return null;
};

export default updateEntry;
