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

const actionAddGoodToCat = (_idCat, nameCat, nameGood) =>
  async (dispatch) => {
    await dispatch(actionPromise('addGoodToCat', gql(` mutation addGood($good:GoodInput){
      GoodUpsert(good:$good){
        _id name 
      }
    }`, {
      good: {
        name: nameGood,
        categories: [{
          name: nameCat,
          _id: _idCat
        }]
      }
    })));

    dispatch(actionCatById(_idCat));
  };

export default actionAddGoodToCat;
