Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip queries when some result from pre hook. #9

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ function PgRestify(config, postInitFunction) {

self.executeWithHooks(req, res, next, 'getCount', function(dbClient, next) {

// Skip if res.pgRestifyResponseBody is not empty, we assume preHook already generated response body
if (res.pgRestifyResponseBody){
return next();
}

var table = self.convertResourceToTable(req.params.resource);

self.validateTable(table, function(err) {
Expand Down Expand Up @@ -179,6 +184,11 @@ function PgRestify(config, postInitFunction) {

self.executeWithHooks(req, res, next, 'get', function(dbClient, next) {

// Skip if res.pgRestifyResponseBody is not empty, we assume preHook already generated response body
if (res.pgRestifyResponseBody){
return next();
}

var table = self.convertResourceToTable(req.params.resource);
var id = req.params.id;

Expand Down Expand Up @@ -259,6 +269,11 @@ function PgRestify(config, postInitFunction) {

self.executeWithHooks(req, res, next, 'put', function(dbClient, next) {

// Skip if res.pgRestifyResponseBody is not empty, we assume preHook already generated response body
if (res.pgRestifyResponseBody){
return next();
}

var table = self.convertResourceToTable(req.params.resource);
var id = req.params.id;
var data = self.convertFieldsToColumns(req.body);
Expand Down Expand Up @@ -299,6 +314,11 @@ function PgRestify(config, postInitFunction) {

self.executeWithHooks(req, res, next, 'delete', function(dbClient, next) {

// Skip if res.pgRestifyResponseBody is not empty, we assume preHook already generated response body
if (res.pgRestifyResponseBody){
return next();
}

var table = self.convertResourceToTable(req.params.resource);
var id = req.params.id;

Expand Down