Reputation: 35
I'm trying to call a Parse Cloud Function from an iOS client but the response.success() function seems to be null. I am getting an error saying that response.success is not a function on the server.
This is my Parse Cloud Function:
Parse.Cloud.define("pruebaQuery", function(request, response) {
const query = new Parse.Query("grupo");
query.equalTo("name", request.params.grupoName);
query.find()
.then((results) => {
for (let i = 0; i < results.length; ++i) {
var grupoId = results[i].get("grupoId");
console.log("GrupoId: " + grupoId);
}
response.success("Success pruebaQuery");
})
.catch(() => {
response.error("grupo lookup failed");
});
});
This is how I call it from the iOS client:
[PFCloud callFunctionInBackground:@"pruebaQuery" withParameters:@{@"grupoName": @"Kinder 3"}
block:^(NSString *object, NSError *error) {
if (!error) {
NSLog(@"CLOUDCode/SUCCESS: %@", object);
}
else {
NSLog(@"CLOUDCode/ERROR %@ code: %ld", error, (long)[error code]);
}
}];
Any clues why the response.success() function is not working?
Upvotes: 3
Views: 2893
Reputation: 520
Since parse-server version ^3.0.0, cloud codes no longer use callbacks. You can use promise or async functions. Here is how you should change your cloud function.
Parse.Cloud.define("pruebaQuery", async request=> {
const query = new Parse.Query("grupo");
query.equalTo("name", request.params.grupoName);
let results;
try{
results = await query.find();
for (let i = 0; i < results.length; ++i) {
let grupoId = results[i].get("grupoId");
console.log("GrupoId: " + grupoId);
}
} catch(error){
throw error.message;
}
});
Upvotes: 6