Skip to content

Instantly share code, notes, and snippets.

@pmbanugo
Created February 6, 2019 16:23
Show Gist options
  • Save pmbanugo/d973b3c65715580b93d4594b8f191898 to your computer and use it in GitHub Desktop.
Save pmbanugo/d973b3c65715580b93d4594b8f191898 to your computer and use it in GitHub Desktop.
describes how findShipment could work for SL vertical
```
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})))
}
```
@pmbanugo
Copy link
Author

pmbanugo commented Feb 8, 2019

I've made a ticket to stating my discovery related this https://github.com/fielded/van-orga/issues/2614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment