0

我正在使用 parse beforeSave方法来保存订单,代码如下:

    //Before save an order - if finish - set priority to 0
    Parse.Cloud.beforeSave("UserToOrders", function(request, response) {
    Parse.Cloud.useMasterKey();
    var preStatus = request.object.get("OrderStatus");
    if (preStatus == "Finish") {
        request.object.set("Priority",0);
        console.log("beforeSave(\"UserToOrders\")\t Order (" + request.object.id + ") Status is 'Finish' So Priority set to '0'");
    }
    else {
        console.log("beforeSave(\"UserToOrders\")\t Order (" + request.object.id + ") Status Changed to: " + preStatus);
        request.object.set("OrderStatus",preStatus);

    }
    response.success();
});

这是日志:

I2016-03-09T20:56:05.779Z]v136 before_save triggered for UserToOrders for user pSi0iCGJJe:
  Input: {"original":{"ACL":{"*":{"read":true},"vxgEWFQ7eu":{"read":true,"write":true}},"OrderStatus":"Ready","OrderStatusActivity":"Active","ResturantID":"g1bzMQEXoj","TimeToBeReady":{"__type":"Date","iso":"2016-03-08T23:35:23.916Z"},"UserETA":{"__type":"Date","iso":"2016-03-08T23:35:23.916Z"},"UserID":"vxgEWFQ7eu","createdAt":"2016-03-08T21:06:06.605Z","objectId":"t3NoxcSp5z","updatedAt":"2016-03-08T21:40:59.538Z"},"update":{"OrderStatus":"Finish","objectId":"t3NoxcSp5z"}}
  Result: Update changed to {"OrderStatus":"Finish","Priority":0}

I2016-03-09T20:56:05.975Z]beforeSave("UserToOrders")     Order (t3NoxcSp5z) Status is 'Finish' So Priority set to '0'

但数据库中没有任何改变。

我想念什么?

谢谢。

4

2 回答 2

0

我已经想通了。这是 ACL 权限问题。一个客户创建的订单,而另一个客户创建的机会。

于 2016-03-09T22:36:11.107 回答
0

var preStatus 中的值与您要保存的值相同...

var preStatus = request.object.get("OrderStatus");

并且您正在“保存”相同的值,您可以删除这一行

request.object.set("OrderStatus",preStatus);

如果不是您想要的,请提供来自“OrderStatus”= Finish 的日志

于 2016-03-09T18:40:10.527 回答