Skip to content

Instantly share code, notes, and snippets.

@bietkul
Created February 11, 2019 20:46
Show Gist options
  • Save bietkul/f7b26b8b63b06c20b7adee7ea62dac35 to your computer and use it in GitHub Desktop.
Save bietkul/f7b26b8b63b06c20b7adee7ea62dac35 to your computer and use it in GitHub Desktop.
Action to fetch a product
import Appbase from "appbase-js";
import { appBaseConfig } from "../../utils/constants";
import createAction from "../utils/actionCreator";
import AppConstants from "../utils/constants";
const appbase = Appbase(appBaseConfig);
export function fetchProduct(id) {
return dispatch => {
dispatch(createAction(AppConstants.PRODUCT.GET));
return appbase.search({
type: appBaseConfig.app,
body: {
query: {
term: {
id
}
}
}
})
.then(res => {
dispatch(createAction(AppConstants.PRODUCT.GET_SUCCESS,
res.hits.hits[0]));
},
error => {
dispatch(createAction(AppConstants.PRODUCT.GET_ERROR, null,
error));
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment