daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Jun 25th, 2015 258 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. this.findWhere = function(conn, coll, obj, cb) {
  2.         if (obj === undefined)
  3.             return cb('Some arguments are missing!');
  4.         if (typeof obj !== 'object')
  5.             return cb('ARG1 must be object!');
  6.         var i = 0,
  7.             arr = [],
  8.             arrObj = [],
  9.             key;
  10.         for (key in obj) {
  11.             var newObj = {};
  12.             newObj['key'] = key;
  13.             newObj['value'] = obj[key];
  14.             arrObj.push(newObj);
  15.         }
  16.         async.eachSeries(arrObj, function(item, callback) {
  17.                 if (i === 0) {
  18.                     new Graph().has(conn,coll,item.key, item.value, 'all', function(err, res) {
  19.                         if (err) cb(err);
  20.                         if (res.length === 0)
  21.                             return cb(null, undefined);
  22.                         if(res.length ===1)
  23.                             return cb(null,res);
  24.                         arr = res;
  25.                         i++;
  26.                         callback();
  27.                     });
  28.                 } else {
  29.                     for (var j = 0; j < arr.length; j++) {
  30.                         if (arr[j][item.key] !== item.value) {
  31.                             arr.splice(j, 1);
  32.                             j--;
  33.                         }
  34.                     }
  35.                     i++;
  36.                     if (i === arrObj.length)
  37.                         cb(null, arr);
  38.                 }
  39.             },
  40.             function(err, res) {});
  41.     }
RAW Paste Data
Top