Adds Hooks API
Adds Parse.Hooks.js in src/cloud-code/Parse.Hooks.js Moves Cloud code related functions in src/cloud-code
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// functions.js
|
||||
// FunctionsRouter.js
|
||||
|
||||
var express = require('express'),
|
||||
Parse = require('parse/node').Parse;
|
||||
Parse = require('parse/node').Parse,
|
||||
triggers = require('../triggers');
|
||||
|
||||
import PromiseRouter from '../PromiseRouter';
|
||||
|
||||
@@ -27,17 +28,21 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
}
|
||||
|
||||
static handleCloudFunction(req) {
|
||||
if (Parse.Cloud.Functions[req.params.functionName]) {
|
||||
var applicationId = req.config.applicationId;
|
||||
var theFunction = triggers.getFunction(req.params.functionName, applicationId);
|
||||
var theValidator = triggers.getValidator(req.params.functionName, applicationId);
|
||||
if (theFunction) {
|
||||
|
||||
const params = Object.assign({}, req.body, req.query);
|
||||
var request = {
|
||||
params: Object.assign({}, req.body, req.query),
|
||||
params: params,
|
||||
master: req.auth && req.auth.isMaster,
|
||||
user: req.auth && req.auth.user,
|
||||
installationId: req.info.installationId
|
||||
};
|
||||
|
||||
if (Parse.Cloud.Validators[req.params.functionName]) {
|
||||
var result = Parse.Cloud.Validators[req.params.functionName](request);
|
||||
if (theValidator && typeof theValidator === "function") {
|
||||
var result = theValidator(request);
|
||||
if (!result) {
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Validation failed.');
|
||||
}
|
||||
@@ -45,7 +50,11 @@ export class FunctionsRouter extends PromiseRouter {
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var response = FunctionsRouter.createResponseObject(resolve, reject);
|
||||
Parse.Cloud.Functions[req.params.functionName](request, response);
|
||||
// Force the keys before the function calls.
|
||||
Parse.applicationId = req.config.applicationId;
|
||||
Parse.javascriptKey = req.config.javascriptKey;
|
||||
Parse.masterKey = req.config.masterKey;
|
||||
theFunction(request, response);
|
||||
});
|
||||
} else {
|
||||
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, 'Invalid function.');
|
||||
|
||||
Reference in New Issue
Block a user