-
-
Save blackjmxx/3a116da8a08dc4951226c8f19c282845 to your computer and use it in GitHub Desktop.
This file contains 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 { | |
destination, | |
pickUpLocation, | |
pickUpDate, | |
availableSeatCount, | |
} = this.state; | |
const travels = []; | |
this.setState({isLoading:true}) | |
let destinationP = fetch( | |
`http://localhost:2020/extended-api/accounts?asset=destination&contains=${destination}` | |
); | |
let pickUpLocationP = fetch( | |
`http://localhost:2020/extended-api/accounts?asset=pickUpLocation&contains=${pickUpLocation}` | |
); | |
let pickUpDateP = fetch( | |
`http://localhost:2020/extended-api/accounts?asset=pickUpDate&contains=${pickUpDate}` | |
); | |
var search = { | |
availableSeatCount, | |
pickUpDate, | |
pickUpLocation, | |
destination | |
}; | |
Promise.all([ | |
destinationP, | |
pickUpLocationP, | |
pickUpDateP, | |
]) | |
.then((values) => { | |
let promises = []; | |
values.forEach((value) => { | |
promises.push(value.json()); | |
}); | |
Promise.all(promises).then((values) => { | |
values.forEach((value) => { | |
console.log(value); | |
value.data.forEach((v) => travels.push({travelId:v.id, carId:v.carId,...v.asset})); | |
}); | |
const filter = {pickUpDate, pickUpLocation, destination} | |
let results = travels.filter(function(item) { | |
for (var key in filter) { | |
if (item[key] === undefined || item[key] !== filter[key]) | |
return false; | |
} | |
return true; | |
}); | |
this.setState({isLoading:false}) | |
let uniquResult = _.uniqBy(results, 'travelId'); | |
this.props.updateTravels({travels:uniquResult, search}) | |
this.props.history.push("/home/results"); | |
}); | |
}) | |
.catch((reason) => { | |
this.setState({isLoading:false}) | |
console.log(reason); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment