Last active
September 5, 2019 19:00
-
-
Save trinadhkoya/455c2489a923e3f8d8f3ed1a13180f86 to your computer and use it in GitHub Desktop.
google-distance-matrix.js
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
const convertOrdersToDeliveryTags = async (orders, address) => { | |
const deliveryTags = _.map(orders, (order) => { | |
return { | |
userName: order.get('user').get('name'), | |
productName: order.get('product').get('name'), | |
orderNumber: order.get('orderNumber'), | |
isPicked: !_.isEmpty(order.get('pickedAt')), | |
isDelivered: !_.isEmpty(order.get('deliveredAt')), | |
isReturned: !_.isEmpty(order.get('returnedAt')), | |
address: order.get('address').get('address'), | |
mapsAddress: order.get('address').get('mapsAddress'), | |
latitude: order.get('address').get('latlong').latitude, | |
longitude: order.get('address').get('latlong').longitude, | |
order: order, | |
chefLat: address[0].get('address').get('latlong')._latitude, | |
chefLong: address[0].get('address').get('latlong')._longitude, | |
}; | |
}); | |
let destinations = deliveryTags.map(order => { | |
return `${order.latitude},${order.longitude}`; | |
}); | |
let origins = [`${deliveryTags[0].chefLat},${deliveryTags[0].chefLong}`]; | |
await googleMapsClient.distanceMatrix({'origins': origins, 'destinations': destinations}, function (err, res) { | |
const filteredArray = []; | |
_.map(deliveryTags, (item) => { | |
if (res.json.destination_addresses.indexOf(item.mapsAddress) !== -1) { | |
filteredArray.push({...item}); | |
} | |
}); | |
return filteredArray; | |
}); | |
return "hello"; | |
}; | |
const doGetTodayOrdersOfSellersByTags = (seller) => async dispatch => { | |
dispatch(getTodayOrdersByTagsRequest()); | |
const orderQuery = new Parse.Query(Order); | |
const today = moment().set('hour', 1).toDate(); | |
const tomorrow = moment().add(1, 'day').set('hour', 1).toDate(); | |
orderQuery.equalTo('seller', seller).greaterThanOrEqualTo('date', today).lessThanOrEqualTo('date', tomorrow).include('user', 'product', 'address').equalTo('orderStatus', 'paid'); | |
orderQuery.find().then((orders) => { | |
dispatch(getTodayOrdersByTagsSuccess(sortOrdersByName(orders))); | |
}).catch((err) => { | |
dispatch(getTodayOrdersByTagsFailure(err)); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment