import Failure from "core/failure";
import { dispatchStatus } from "store";
import * as actionTypes from "./servicesActionTypes";
import { loadServices } from "./servicesService";

const getServicesAction = () => (dispatch: any) => {
  dispatch({ type: actionTypes.GET_SERVICES });

  return loadServices()
    .then((services) =>
      dispatchStatus(actionTypes.GET_SERVICES, ".success", services)(dispatch)
    )
    .catch((failure: Failure) => {
      dispatchStatus(actionTypes.GET_SERVICES, ".failure", failure)(dispatch);
    });
};


export {
  getServicesAction,
};
