Created
March 14, 2018 09:25
-
-
Save innerdaze/7c4223135e8b538f1b41a00fcf50d4d6 to your computer and use it in GitHub Desktop.
Wastage Operations
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 { pluck } from 'ramda' | |
import { callApi } from '~features/network/operations' | |
import { orderOperations, orderSelectors } from '~features/order' | |
import actions from './actions' | |
import selectors from './selectors' | |
const wastageActions = actions.wastage | |
export const fetchWastageTypes = () => dispatch => { | |
dispatch(wastageActions.requestWastageTypes()) | |
return dispatch( | |
callApi({ | |
service: 'WastageService.GetWastageTypes', | |
success(data) { | |
dispatch( | |
wastageActions.receiveWastageTypes( | |
data.result.Result.ListOfWastageTypes | |
) | |
) | |
}, | |
failure(error) { | |
dispatch(wastageActions.receiveWastageTypes(error)) | |
} | |
}) | |
) | |
} | |
export const processWastage = () => (dispatch, getState) => { | |
dispatch(wastageActions.requestProcessWastage()) | |
const wastageEntities = selectors.wastageEntitiesListSelector(getState()) | |
return dispatch( | |
callApi({ | |
service: 'WastageService.ProcessWastage', | |
params: { | |
ListOfWastageLines: wastageEntities | |
}, | |
success(data) { | |
dispatch(wastageActions.receiveProcessWastage()) | |
dispatch(orderOperations.receiveProcessOrders()) | |
dispatch( | |
orderOperations.succeedProcessOrders(pluck('_id', wastageEntities)) | |
) | |
}, | |
failure(error) { | |
dispatch(wastageActions.receiveProcessWastage()) | |
dispatch(orderOperations.receiveProcessOrders()) | |
dispatch(orderOperations.succeedProcessOrders(error)) | |
} | |
}) | |
) | |
} | |
export default { | |
...actions.wastage, | |
fetchWastageTypes, | |
processWastage | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment