
import {gql, urlUpload, actionPromise} from "./index";

const actionImgOne = (_id) => {
  const queryJson = JSON.stringify([{
    "_id": `${_id}`
  }]);
  return (actionPromise('image', gql(
    `query findImg($query: String)  {
      ImageFindOne(query: $query) {
        _id
        createdAt
        url
      }
    }`, {query: queryJson}
  )))
}

const updateImgAction = selectedFile => {
  const formData = new FormData();

  formData.append('photo', selectedFile);

  return actionPromise("photo", fetch(`${urlUpload}/upload`, {
    method: 'POST',
    headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
    body: formData,
  }).then((response) => response.json()))
};


  

  

  export default updateImgAction;