import { Business } from "../api/agent"; import { businessActions } from "./business-slice"; export const fetchBusinesses = () => { return async (dispatch: any) => { try { const businesses = await fetchData(); console.log('f',businesses) dispatch(businessActions.fetchBusiness(businesses)); } catch (e) { console.log("Error in Outlet fetching...."); } }; }; export const createBusinesses = (newBusiness: any) => { return async (dispatch: any) => { try { const response = await createBusiness(newBusiness); console.log("Business Created ", response); } catch (e) { console.log("Error in Business creating....", e); } }; }; const fetchData = async () => { const response = await Business.list(); if (!response) { throw new Error("Could not fetch businesses"); } return response; }; const createBusiness = async (newBusiness: any) => { const response = await Business.create(newBusiness); if (!response) { throw new Error("Could not create businesses"); } return response; }; export const updateBusiness = async (oldBusiness:any) =>{ const response = await Business.update(oldBusiness); if (!response) { throw new Error("Could not find the business"); } return response; }