-
-
Save chapel/6260615 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) { | |
var userMap = {}; | |
var friendIds = users.map(function (user) { | |
userMap[user._id] = user; | |
return user._id; | |
}); | |
Friend.find({userId: req.signedCookies.userid, friend_id: {$in: friendIds}, friend_status: 3}, function(err, friends) { | |
if(err || !friends.length) { | |
console.log("houston we got a problem.") | |
return callback(err) | |
} | |
friends = friends.map(function (friend) { | |
return userMap[friend._id]; | |
}); | |
callback(null, friends); | |
}); | |
} | |
], | |
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