Created
February 25, 2015 03:17
-
-
Save jeffhuangtw/01ea94bc0cb801f67272 to your computer and use it in GitHub Desktop.
Parse.com cloud code to prevent users from making duplicate submissions
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("Requests", function(request, response) { | |
var postObj = new Parse.Object("Posts"); | |
postObj.set("objectId", request.object.get("Post_Pointer")); | |
var query = new Parse.Query("Requests"); | |
query.equalTo("Post_Pointer", postObj); | |
query.equalTo("Requester", Parse.User.current()); | |
query.first({ | |
success: function(object) { | |
if (object) { | |
response.error("A request has already been submitted."); | |
} 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