Created
February 6, 2019 16:23
-
-
Save pmbanugo/d973b3c65715580b93d4594b8f191898 to your computer and use it in GitHub Desktop.
describes how findShipment could work for SL vertical
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
``` | |
export const findShipments = (location, locationIsGeoLocation) => async (dispatch) => { | |
dispatch(asyncRequest({reducerName})) | |
const store = getStore() | |
const promises = [ | |
store.shipment.find({location, locationIsGeoLocation}) | |
] | |
// If the location is a geo location we need to filter the shipments to only | |
// include those that are valid locations for the users geo location. This way | |
// we exclude shipments for locations that the user does not have the funder. | |
// For that we need to get the locations the user can see. | |
if (locationIsGeoLocation) { | |
const mdApi = getMDApi() | |
promises.push( | |
mdApi.location.listChildren(location.id) | |
) | |
} | |
return Promise.all(promises) | |
.then(([shipments, locations]) => { | |
let locationIdSet | |
if (locationIsGeoLocation) { | |
locationIdSet = new Set(locations.map(l => l._id)) | |
} else { | |
locationIdSet = new Set([location.id]) | |
} | |
const destinedShipments = shipments.filter(shipment => locationIdSet.has(shipment.destination.id) && shipment.status !== 'new') | |
const originShipments = shipments.filter(shipment => locationIdSet.has(shipment.origin.id)) | |
shipments = [...originShipments, ...destinedShipments] | |
dispatch(asyncReceive({reducerName})) | |
dispatch({type: RECEIVE_SHIPMENTS, shipments}) | |
}) | |
.catch(error => dispatch(asyncReceiveError({reducerName, error}))) | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've made a ticket to stating my discovery related this https://github.com/fielded/van-orga/issues/2614