Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Cloud Code callback not working

I am building an app with friends relations using Parse Cloud Code.

When Alice sends Bob a friend request, it is a notification of type 71. When Bob answers he sends a notification of type 8.

On the server, when a type 8 notification is sent, first some friendship relations are proceeded. They are: removing from both users from each other "potential friend list" and adding to "friend list" instead.

Afterwards, the notification of type 71 should be changed to a type 1 notification.

For some reasons I've been struggling for 24h to make it work. I simply cant proceed those two functions one after the other: the second one is never executed. Here is my code

Parse.Cloud.afterSave("Notification", function(request, response) {

Parse.Cloud.useMasterKey();
var downQuery = new Parse.Query("Notification");

var namnamA = request.object.get('nameA');
var namnamB = request.object.get('nameB');
var tytype = request.object.get('type');
var alice = Parse.User.current();
if (tytype === 8){

var bobQuery = new Parse.Query(Parse.User);
bobQuery.equalTo("username", namnamB);
bobQuery.first().then(function(bob) {
    var alicesRelation = alice.relation("friendsList");
    var alicesPotRelation = alice.relation("potFriendsList");
    var bobsRelation = bob.relation("friendsList");
    var bobsPotRelation = bob.relation("potFriendsList");
    alicesPotRelation.remove(bob);
    alicesRelation.add(bob);
    bobsPotRelation.remove(alice);
    bobsRelation.add(alice);        

    return Parse.Object.saveAll([alice, bob]);


}).then(function() {

    downQuery.equalTo('nameA', namnamB);
    downQuery.equalTo('nameB', namnamA);
    downQuery.equalTo('type', 71);
    return downQuery.find();

}).then(function(notizz) {

    notizz.set('type', 1);
    return Parse.Object.saveAll([notizz]);

}).then(function() {
    console.log("success " + arguments);
    response.success(arguments);    

}), function(error) {
    console.log("error " + error.message);
    response.error(error);

} 
}
});

Any help would greatly improve the life expectancy of my computer. Thank you.

like image 782
Quentin Malgaud Avatar asked Jan 21 '26 06:01

Quentin Malgaud


1 Answers

aftersave does not have a response, only a request. https://parse.com/docs/js/guide

Therefore, you do not need to (and should not) be using a response.

Further, when you call return, it exits the function

like image 111
papergodzilla Avatar answered Jan 23 '26 18:01

papergodzilla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!