Added ability to add a validation function to a Cloud Code function

This commit is contained in:
Björn Kaiser
2016-01-31 20:08:07 +00:00
parent 522abdf606
commit e73dcf4287
2 changed files with 12 additions and 1 deletions

View File

@@ -10,6 +10,14 @@ var router = new PromiseRouter();
function handleCloudFunction(req) {
// TODO: set user from req.auth
if (Parse.Cloud.Functions[req.params.functionName]) {
// Run the validator for this function first
if (Parse.Cloud.Validators[req.params.functionName]) {
var result = Parse.Cloud.Validators[req.params.functionName](req.body);
if (!result) {
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Validation failed.');
}
}
return new Promise(function (resolve, reject) {
var response = createResponseObject(resolve, reject);
var request = {