import { actionPromise, actionCatById } from '.';
import gql from '../api';

const actionChangeOneGood = (_id, _idCat, name, description, price, idImg) =>
  async (dispatch) => {
    await dispatch(actionPromise('changeGood', gql(`mutation changeGood($good:GoodInput){
      GoodUpsert(good:$good){
        _id name
      }
    }`, {
      good: {
        _id,
        description,
        name,
        price: +price,
        images: idImg
      }
    })));

    dispatch(actionCatById(_idCat));
  };

export default actionChangeOneGood;
