解析云代码回调无法正常工作

时间:2015-04-20 19:15:07

标签: javascript parse-platform cloud-code

我正在使用Parse Cloud Code构建一个与朋友关系的应用程序。

当Alice向Bob发送朋友请求时,它是类型71的通知。 当Bob回答时,他发送了类型为8的通知。

在服务器上,当发送类型8通知时,首先进行一些友谊关系。它们是:从两个用户中删除彼此"潜在的朋友列表"并添加到"朋友列表"代替。

之后,类型71的通知应更改为类型1通知。

出于某些原因,我一直在努力工作24小时才能使其发挥作用。我不能一个接一个地继续这两个函数:第二个函数永远不会被执行。这是我的代码

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);

} 
}
});

任何帮助都会大大提高我电脑的预期寿命。谢谢。

1 个答案:

答案 0 :(得分:1)

aftersave没有响应,只有请求。 https://parse.com/docs/js/guide

因此,您不需要(也不应该)使用响应。

此外,当您调用return时,它会退出函数