Skip to content

Instantly share code, notes, and snippets.

@jeffhuangtw
Created February 26, 2015 02:30
Show Gist options
  • Save jeffhuangtw/67d2c2a33eeb3c6644ce to your computer and use it in GitHub Desktop.
Save jeffhuangtw/67d2c2a33eeb3c6644ce to your computer and use it in GitHub Desktop.
parse cloud code sample code
Parse.Cloud.beforeSave("Posts", function(request, response) {
if (request.object.existed()) {
return response.success(); // the Post already exist, this must be an Update action
}
// do a query to "Posts" to check the oldest related "Posts" to current user
var query = new Parse.Query("Posts");
query.equalTo("PostUser", Parse.User.current());
query.equalTo("Topic", YOUR_REFERENCED_TOPIC_OBJECT); // assume you are want to reference it by pointer
query.descending("createdAt");
query.first({
success: function(object) {
if (object) {
// check for the time period limitation
response.error("Timeout.");
} else {
response.success();
}
},
error: function(error) {
response.error("Could not save request. Error: " + error);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment