JavaScript Nested promise with Parse.com nested promise in node js,nested promise in javascript,nested

I've a function to update the DB rows one by one with Parse's promise

exports.update = function (items, successHandler, errorHandler) {

    Parse.Cloud.useMasterKey();
    var Item = Parse.Object.extend("Item");

    Parse.Promise.as().then(function () {
        var promises = [];

        for (var i = 0; i < items.length; i++) {                
                (function (j) {  //create new closure so i changes with each callback
                    var query = new Parse.Query(Item);
                    query.equalTo("sku", items[j]['sku'];);

                    promises.push(query.find({
                        success: function (results) {
                            if (results.length === 1) {
                                var object = results[0];

                                console.log('Item exists, now updating..');

                                return object.save(items[j]).then(function () {
                                    console.log("Item saved"); // never called, why?

                                }, function (error) {
                                    console.error("Item not saved with error: " + error.message); // never called, why?
                                });
                            }
                        },
                        error: function (error) {
                            console.error("Failure during querying..");
                        }
                    }));
                })(i);
        }

        return Parse.Promise.when(promises);

    }).then(function () {
            return successHandler("Item updated.");
        }, function (error) {
            return errorHandler(error);
        }
    );
};

The problem is, the object.save is actually called and data is being saved in the DB, however, the following two promises are never called, not matter success or not.

Answer:1

Is there a shorter more efficient way of doing this? it seems a little hefty and I just want to know if it can be condensed? var y = [] for(let i=0;i < word.length;++i){ if(word[i] == "A"||...

Is there a shorter more efficient way of doing this? it seems a little hefty and I just want to know if it can be condensed? var y = [] for(let i=0;i < word.length;++i){ if(word[i] == "A"||...

In my app I have several classes which are used to create XML strings. Each class has a few methods that take some arguments and return a string. I want to specify this limitation so that methods with ...

In my app I have several classes which are used to create XML strings. Each class has a few methods that take some arguments and return a string. I want to specify this limitation so that methods with ...

In my SPA I am using axios to make requests to the API. I currently use axios request interceptors to add auth headers to requests but I also wanted to use them to catch 401 errors and remove the ...

In my SPA I am using axios to make requests to the API. I currently use axios request interceptors to add auth headers to requests but I also wanted to use them to catch 401 errors and remove the ...

  1. axios catch request

I need regular expression to not allow only whitespaces in a field(the user should not enter just whitespaces in the field) but it can allow completely empty field and it can also allow string with ...

I need regular expression to not allow only whitespaces in a field(the user should not enter just whitespaces in the field) but it can allow completely empty field and it can also allow string with ...

  1. regular expression javascript tester
  2. regular expression javascript example
  3. regular expression javascript tutorial
  4. regular expression javascript test
  5. regular expression javascript phone number
  6. regular expression javascript mdn
  7. regular expression javascript generator
  8. regular expression javascript match
  9. regular expression javascript email
  10. regular expression javascript w
  11. regular expression javascript or
  12. regular expression javascript phone number validation
  13. regular expression javascript replace
  14. regular expression javascript space
  15. regular expression javascript validation
  16. regular expression javascript special characters
  17. regular expression javascript escape characters
  18. regular expression javascript for name
  19. regular expression javascript numbers only
  20. regular expression javascript for password