How to return Parse promise from the cloud code module?

Does anyone know how to return a Promise result from a cloud code module? I use examples here , but he continues to tell me that the parameters are undefined (or nothing if I check first with (options).

I call the function with module.functionas a promise, but still not getting the results.

And ideas?

Edit: I can make it work, but by calling:

module.function({},{
 success:function(res){
  //do something
 }, 
 error:function(err){
  //handle error
 }
})

but this is not very cool, since 1) I have to insert an empty object there. 2) I can not make the object work as a promise and, therefore, lose the ability to chain.

+4
source share
1

, promises. , , , , , .

:

// in 'cloud/somemodule.js'

// return a promise to find instances of SomeObject
exports.someFunction = function(someValue) {
    var query = new Parse.Query("SomeObject");
    query.equalTo("someProperty", someValue);
    return query.find();
};

, :

// in 'cloud/main.js'
var SomeModule = require('cloud/somemodule.js');

Parse.Cloud.define("useTheModule", function(request, response) {
    var value = request.params.value;
    // use the module by mentioning it
    // the promise returned by someFunction can be chained with .then()
    SomeModule.someFunction(value).then(function(result) {
        response.success(result);
    }, function(error) {
        response.error(error);
    });
});
+4

Source: https://habr.com/ru/post/1605814/


All Articles