0

I'm trying to make a cloud function which saves the sender's objectId and username as an array, inside the array "request", for the target and have the target's objectId and username saved as an array, in the array "pending" for the sender.

Parse.Cloud.define("newGameRequest", function(request, response) {//A
// Get the user who called the function
var user = request.user;

var target;

var query = new Parse.Query(Parse.User);
query.get(request.params.friendId, {
success: function(object) {

        var target = object;

        var friendInfo = [target.objectId, target.username];
        var userInfo = [user.objectId, user.username];

        user.add("pending",friendInfo);
        target.add("request",userInfo);


         Parse.Object.saveAll([user, target], { useMasterKey: true });


  response.success("Success");

    },
    error: function(object, error) {
        response.error(error);
    }
});

});

Looking in the data browser shows that the arrays for each respective user were saved, but saved with null values only ([[null,null]] for both).

The call is from an iOS device and is the following:

[PFCloud callFunctionInBackground:@"newGameRequest"
                   withParameters:@{@"friendId": self.friend.objectId}
                            block:^(NSString *result, NSError *error) {
                                if (!error) {

                                }
                                else {
                                    NSLog(@"%@",result);
                                }
                            }];

self.friend.objectId has been tested and is the right result.

What is the issue with my cloud code?

SMD01
  • 101
  • 1
  • 13

1 Answers1

0

I'm an idiot.

getting the object Id of user is the like the following:

                    user.id

and getting the username is done like this:

                   user.getUsername()
SMD01
  • 101
  • 1
  • 13