JSFiddle - React, Tailwind, and code Playground
by Valeriy
JavaScript
function getFacilityId() {
console.log('Start to fetch FacilityId');
let promise = new Promise(function(resolve, reject) {
setTimeout(function() {
Math.random() > .5 ? resolve({res:"UserId"}) : reject("Facility Id can't be fetching" )
}, 2000)
});
return promise;
}
function getUserId(){
console.log('Start to fetch UserId');
return new Promise(function(resolve, reject){
setTimeout(() => resolve("UserId"), 2000)
});
};
function concatQueries(facilityId, userId) {
console.log('Concating');
return `/check/${userId}/${facilityId}`
};
function sendThirdQuery(params) {
console.log('sendThirdQuery');
console.log('Send post with params')
};
getFacilityId({})
.then(getUserId)
.then(concatQueries("facilityId", "userId"))
.then(sendThirdQuery('params'))
.catch(error => console.log(error))