Created
February 26, 2015 02:30
-
-
Save jeffhuangtw/67d2c2a33eeb3c6644ce to your computer and use it in GitHub Desktop.
parse cloud code sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/parse-developers/E9ZH6oyNQfE