Created
February 11, 2019 20:46
-
-
Save bietkul/f7b26b8b63b06c20b7adee7ea62dac35 to your computer and use it in GitHub Desktop.
Action to fetch a product
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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