Created
August 18, 2013 08:39
-
-
Save anonymous/6260605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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