Added ability to add a validation function to a Cloud Code function
This commit is contained in:
@@ -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 = {
|
||||
|
||||
5
index.js
5
index.js
@@ -113,14 +113,17 @@ function ParseServer(args) {
|
||||
|
||||
function addParseCloud() {
|
||||
Parse.Cloud.Functions = {};
|
||||
Parse.Cloud.Validators = {};
|
||||
Parse.Cloud.Triggers = {
|
||||
beforeSave: {},
|
||||
beforeDelete: {},
|
||||
afterSave: {},
|
||||
afterDelete: {}
|
||||
};
|
||||
Parse.Cloud.define = function(functionName, handler) {
|
||||
|
||||
Parse.Cloud.define = function(functionName, handler, validationHandler) {
|
||||
Parse.Cloud.Functions[functionName] = handler;
|
||||
Parse.Cloud.Validators[functionName] = validationHandler;
|
||||
};
|
||||
Parse.Cloud.beforeSave = function(parseClass, handler) {
|
||||
var className = getClassName(parseClass);
|
||||
|
||||
Reference in New Issue
Block a user