Reputation: 415
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.
Upvotes: 3
Views: 246
Reputation: 161
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
Upvotes: 1