From 5f42533603fe4258c80d907f7744e67dabac8394 Mon Sep 17 00:00:00 2001 From: Semen Ogorodnik Date: Mon, 5 Oct 2015 17:14:12 +0300 Subject: [PATCH 1/3] Added posibility to skip toJSON and then filter objects by user own function --- lib/express_promise.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/express_promise.js b/lib/express_promise.js index cf08e0c..29c9766 100644 --- a/lib/express_promise.js +++ b/lib/express_promise.js @@ -44,7 +44,7 @@ var resolveAsync = function(object, callback, count, options) { return callback(null, object); } - if (typeof object.toJSON === 'function') { + if (typeof object.toJSON === 'function' && !options.disableJSONify && !options.disableJSONify(object)) { object = object.toJSON(); if (!object || typeof object !== 'object') { return callback(null, object); @@ -88,6 +88,8 @@ var resolveAsync = function(object, callback, count, options) { item.exec(function(err, result) { handleDone(err, result); }); + } else if(options.objectFilter && options.objectFilter(object[item.key])) { + handleDone(null, object[item.key]); } else { resolveAsync(object[item.key], handleDone, count - 1, options); } @@ -188,16 +190,14 @@ var expressPromise = function(options) { return next(err); } if (typeof status !== 'undefined') { - res.status(status); - originalResSend(result); + originalResSend(status, result); } else { originalResSend(result); } }, options.maxPromise, options); } else { if (status) { - res.status(status); - originalResSend(body); + originalResSend(status, body); } else { originalResSend(body); } From e4d1ed1d026a5e9ed909b5281d6a03de4b432563 Mon Sep 17 00:00:00 2001 From: Semen Ogorodnik Date: Mon, 5 Oct 2015 17:26:57 +0300 Subject: [PATCH 2/3] Fixed problem with disableJSONify function --- lib/express_promise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/express_promise.js b/lib/express_promise.js index 29c9766..169f849 100644 --- a/lib/express_promise.js +++ b/lib/express_promise.js @@ -44,7 +44,7 @@ var resolveAsync = function(object, callback, count, options) { return callback(null, object); } - if (typeof object.toJSON === 'function' && !options.disableJSONify && !options.disableJSONify(object)) { + if (typeof object.toJSON === 'function' && !(options.disableJSONify && options.disableJSONify(object))) { object = object.toJSON(); if (!object || typeof object !== 'object') { return callback(null, object); @@ -89,7 +89,7 @@ var resolveAsync = function(object, callback, count, options) { handleDone(err, result); }); } else if(options.objectFilter && options.objectFilter(object[item.key])) { - handleDone(null, object[item.key]); + handleDone(null, object[item.key]); } else { resolveAsync(object[item.key], handleDone, count - 1, options); } From a7785bd0c8e8468af6a2b21fa9db44801080e22d Mon Sep 17 00:00:00 2001 From: Semen Ogorodnik Date: Mon, 5 Oct 2015 17:31:47 +0300 Subject: [PATCH 3/3] Now all tests passing --- lib/express_promise.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/express_promise.js b/lib/express_promise.js index 169f849..9dda44e 100644 --- a/lib/express_promise.js +++ b/lib/express_promise.js @@ -190,14 +190,16 @@ var expressPromise = function(options) { return next(err); } if (typeof status !== 'undefined') { - originalResSend(status, result); + res.status(status); + originalResSend(result); } else { originalResSend(result); } }, options.maxPromise, options); } else { if (status) { - originalResSend(status, body); + res.status(status); + originalResSend(result); } else { originalResSend(body); }