我正在覆盖BeforeSave
in CloudCode
for Parse.com
。这是我在logs
:
Input: {"original":null,"update":{"password":"5428","phone_number":"56858","ACL":{"T1pXElsPPT":{"read":true,"write":true}},"config":"{}","creator":"T1pXElsPPT","name":"quarta prova"}}
Result: Update changed to {"config":"{}","creator":"T1pXElsPPT","name":"quarta prova","password":"5428","phone_number":"56858","ACL":{"T1pXElsPPT":{"read":true,"write":true}}}
我只需要检查BeforeSave
用户是否正在创建new
对象,而不是当他是updating
一个对象时old
。这是我到目前为止所做的:
Parse.Cloud.beforeSave("tracker", function(request, response) {
var spaces = availableSpace(request.user.id);
if (request.original != undefined && request.original === null) {
if (spaces == 0) {
response.error("No available spaces");
} else if (spaces >= 1) {
response.success();
} else if (spaces < 0) {
response.error("Lookup error");
}
} else {
response.success();
}
});
但它似乎original
不在请求对象中(所以它是未定义的,总是导致 a response.success();
)
有没有办法检查original
或另一种方法来检查这是一个insert
还是一个update
?