Search code examples
javascriptswiftparse-platformparse-cloud-code

Save to a PFUser using Cloud code Swift


I'm trying to modify PFUsers using Cloud Code. I have just recently been introduced to JavaScript so please forgive any blatant syntax mistakes.

Main.js

Parse.Cloud.define('addWinsLosses', function(request,responce) {

    Parse.Cloud.useMasterKey();

    var winnerUserId = request.params.winnerUserId, 
        loserUserId = resquest.params.loserUserId

    var User = Parse.Object.extend('_User'),
        winner = new User({ objectId: winnerUserId });

    winner.set('wins', 1)

    winner.save(null, {
        success: function (winner) {
            response.success();
            console.log("Save ok");
        },
        error: function (error) {
            response.error(error);
            console.log("Error");
        }
    });

    var User = Parse.Object.extend('_User'),
        loser = new User({ objectId: loserUserId });

    loser.set('losses', 1)

    loser.save(null, {
        success: function (loser) {
            response.success();
            console.log("Save ok");
        },
        error: function (error) {
            response.error(error);
            console.log("Error");
        }
    });
});

As you can see above I am trying to send up PFUser Id strings to then modify the specific PFUsers. I am suspecting that it is the transition from PFUser Id to PFUser pointer that is the issue here.

I'm getting this error:

[Error]: ReferenceError: resquest is not defined
        at main.js:10:17 (Code: 141, Version: 1.9.1)
    Optional(Error Domain=Parse Code=141 "ReferenceError: resquest is not defined
        at main.js:10:17" UserInfo={code=141, error=ReferenceError: resquest is not defined
        at main.js:10:17, temporary=0, NSLocalizedDescription=ReferenceError: resquest is not defined
        at main.js:10:17})

The line of code that the error is referencing is this one winner.save(null, {

Here is the code in my View Controller:

PFCloud.callFunctionInBackground("addWinsLosses", withParameters: ["winnerUserId" : (judgedGame.winner?.objectId)!, "loserUserId" : (judgedGame.winner?.objectId)!], block: { (result: AnyObject?, error: NSError?) -> Void in

                        if (error == nil) {

                        } else {
                            print(error)
                        }
                    })
                }

One other detail that I should mention is that I subclassed the PFUser which I don't believe should make a difference but I'm throwing that out there just in case.

What is the issue with my code?


Solution

  • You've misspelled response as responce in your funciton defnition.

    Also, you're redefining the User variable on line 22, but that won't cause a crash.