我正在覆盖BeforeSave
CloudCode
中的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
});
但似乎response.success();
不在请求对象中(所以它未定义,总是导致original
)
有没有办法检查insert
或其他方式来检查这是update
还是{{1}}?
答案 0 :(得分:4)
您可以使用Parse.Object.isNew()
Parse.Cloud.beforeSave("tracker", function(request, response) {
var spaces = availableSpace(request.user.id);
if (request.object.isNew()) {
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();
}
});