I have tried to understand how promises work, but I don't get it why I need press my button more than few times this promise chain to work.
- First function creates new user and returns a promise.
- Second updates other system if user has a car.
- Third should update user object when car id is received.
When I press the button only CreateUser
is fired. If I press button again it will also fire UpdateModel
.
CreateUser(newUser).then((userObject) => {
if(userObject.car) {
UpdateModel(userObject.objectId, userObject.car).then((carId) => {
userObject.car = carId;
UpdateUser(userObject).then((updatedUser) => {
this.moveNextPage(updatedUser);
});
}, (error) => {
console.log(error);
});
} else {
this.moveNextPage(userObject);
}
}, (error) => {
console.log(error);
})