Skip to content

Commit

Permalink
fix:  query  find with no callback
Browse files Browse the repository at this point in the history
  • Loading branch information
XadillaX committed Oct 20, 2016
1 parent bc67f87 commit 8cf2d79
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,19 @@ class ToshihikoQuery {
* @returns {Promise} the promise object
*/
find(callback, toJSON, options) {
if(typeof callback !== "function") {
options = toJSON;
toJSON = callback;
callback = emptyFunc;
}
if(typeof toJSON === "object") {
options = toJSON;
toJSON = false;
for(let i = 0; i < arguments.length; i++) {
switch(typeof arguments[i]) {
case "function": callback = arguments[i]; break;
case "boolean": toJSON = arguments[i]; break;
case "object": options = arguments[i]; break;
default: break;
}
}

if(typeof callback !== "function") callback = emptyFunc;
if(typeof toJSON !== "boolean") toJSON = false;
if(typeof options !== "object") options = {};
options = options || {};
if(undefined === callback) callback = emptyFunc;

callback = common.promisify(callback);
const self = this;
Expand Down

0 comments on commit 8cf2d79

Please sign in to comment.