Passing in a Parse Object to a cloud code function

I have a cloud code function that creates a GuestlistInvite

An object. It accepts a phone number, a guest list object, and a guest object.

I call the function as follows:

Parse.Cloud.run('createGuestlistInviteForExistingUser', {
   phoneNumber: phoneNumber,
   guestlist: guestlist,
   guest: user
   }).then(function(guestlistInvite) {
      response.success(successfully created guestlistInvite');
 }); 

Both user and user are pointers. However, in my logs I get an error message:

Result: Error: Parse Objects not allowed here

Any idea why this is happening?

Parse.Cloud.define('createGuestlistInviteForExistingUser', function(request, response) {

  var phoneNumber = request.params.phoneNumber;
  var guestlist = request.params.guestlist;
  var guest = request.params.guest;

  var guestlistInvite = new Parse.Object("GuestlistInvite");

  guestlistInvite.save({
    phoneNumber: phoneNumber,
    Guestlist: guestlist,
    Guest: guest,
    checkInStatus: false,
    response: 0
  }).then(function(guestlistInvite) {
    console.log('guestlistInvite for existing user was created');
    response.success(guestlistInvite);
  }, function(error) {
    response.error('guestlistInvite was not saved');
  });

});
+4
source share
1 answer

You cannot send the entire PFObject as a request parameter for calling cloud functions.

PFObjectId , , Cloud.

, , promises:

Parse.Cloud.define("myFunction", functoin(request, response)
{
    var MyObject = Parse.Object.extend("MyObjectClass"); //You can put this at the top of your cloud code file so you don't have to do it in every function
    var myObject = new MyObject(); 
    var myObjectId = request.params.myObjectId;

    myObject.id = myObjectId;
    myObject.fetch().then
    (
        function( myObject )
        {
            //do stuff with it
        },
        function( error )
        {
            response.error("There was an error trying to fetch MyObjectClass with objectId " + myObjectId + ": " + error.message);
        }
    );
});
+4

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


All Articles