As I work on developing an iOS app using Parse SDK hosted on back4app, I have encountered a problem with implementing a new feature. In the back4app dashboard, my app hosts a main.js file in Cloud Code that successfully sends push notifications when called by code.
Recently, I added a blockuser.js
file to my Cloud Code. This file is supposed to edit the isBlocked
column (which is of type Boolean) of a specific user in the _User class and set it to true
. Here's the code snippet I used:
Parse.Cloud.define("blockUser", function(request, response) {
var userId = request.params.userId,
var User = Parse.Object.extend('_User'),
user = new User({ objectId: userId });
user.set('isBlocked', true);
Parse.Cloud.useMasterKey();
user.save().then(function(user) {
response.success(user);
}, function(error) {
response.error(error)
});
});
Additionally, here is the Swift code snippet I wrote to call the aforementioned function:
let request = ["userId" : userPointer.objectId!] as [String : Any]
PFCloud.callFunction(inBackground: "blockUser", withParameters: request as [String : Any], block: { (results, error) in
if error == nil {
print ("\(userPointer["username"]!) has been blocked!")
// error in cloud code
} else {
print ("\(error!.localizedDescription)")
}})
Upon checking the Xcode console, I noticed this message being printed out:
[Error]: Invalid function. (Code: 141, Version: 1.14.2)
It is clear that the blockUser
function is not functioning as expected. Can anyone provide insights into what might be going wrong with either the .js or Swift code?