I am a new developer and am working on a rather complex scenario where, when the user saves, there might be a lock and the user has the chance to over ride the lock. If there is a lock, since REST is stateless, the object I was sending on the PUT is lost, so I have to allow the user to over ride the lock and then make the put request again.
In the second if check you can see that I have a nested promise. From what I know about promises vs. callbacks, this defeats the purpose of using promises. I read through some other answers, but did not understand the concept of returning a promise in the inner/nested promise. How could I refactor the code below to make it more in line with best practices and not nest promises?
//the user chooses to over ride someone else's lock
$scope.$on('forceLockAfterModalSubmit', function (e, data) {
if (!$scope.newItemCreatedIsLocked) {
$scope.setLockForCurrentUser();
$scope.editMode = true;
}
if ($scope.newItemCreatedIsLocked) {
service.forceLock($scope.id).then(function () {
itemService.updateItem($scope.itemForRequestBeforeLockResponse).then(function () {
$scope.postPUTRequestActions($scope.itemForRequestBeforeLockResponse);
})
}, function (err) {
console.log(err);
})
}
})