Skip to content

Instantly share code, notes, and snippets.

Created August 18, 2013 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6260605 to your computer and use it in GitHub Desktop.
Save anonymous/6260605 to your computer and use it in GitHub Desktop.
exports.searchContactPost = function(req, res) {
if(req.body.searchContacts === '') { res.send('Oops you searching for nothing, well here is nothing!'); };
async.waterfall([
function(callback) {
User.find({$or:[
{firstName: req.body.searchContacts.toLowerCase()},
{lastName: req.body.searchContacts.toLowerCase()},
{email: req.body.searchContacts.toLowerCase()}]
}, function(err, users) {
if(err || users.length === 0) { res.send(err);}
callback(null, users)
});
},
function(users, callback) {
async.filterSeries(users, function(friend, next) {
//console.log(friend);
Friend.findOne({userId: req.signedCookies.userid, friend_id: friend}, function(err, user) {
if(err) {
console.log("houston we got a problem.")
var fav = user.favorites;
var object = {'fav': fav, 'notes': user.notes, 'labels': user.labels, 'user': friend, 'status': user.friend_status};
console.log('object');
console.log(object);
console.log(object.status);
next(object.status === 3);
}
// console.log(user);
//console.log(object.user.friend_status === 3);
});
}, function(friendResults){
console.log(friendResults);
callback(null, friendResults);
});
}
],
function(err, results) {
console.log(results);
res.render('contactListResults', {title: 'Weblio', friendsFound: results});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment