Skip to content

Instantly share code, notes, and snippets.

@blackjmxx
Created November 30, 2020 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackjmxx/3a116da8a08dc4951226c8f19c282845 to your computer and use it in GitHub Desktop.
Save blackjmxx/3a116da8a08dc4951226c8f19c282845 to your computer and use it in GitHub Desktop.
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