Skip to content

Instantly share code, notes, and snippets.

@innerdaze
Created March 14, 2018 09:25
Show Gist options
  • Save innerdaze/7c4223135e8b538f1b41a00fcf50d4d6 to your computer and use it in GitHub Desktop.
Save innerdaze/7c4223135e8b538f1b41a00fcf50d4d6 to your computer and use it in GitHub Desktop.
Wastage Operations
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