-
-
Save nhunzaker/6262330 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) { | |
var contact = req.body.searchContacts.toLowerCase() | |
User.find({$or:[ | |
{firstName: contact }, | |
{lastName : contact }, | |
{email : contact }] | |
}, function(err, users) { | |
if (err || users.length === 0) return res.send(err); | |
callback(null, users); | |
}); | |
}, | |
function(users, callback) { | |
Friend.find({ | |
userId: req.signedCookies.userid, | |
// This probably doesn't work, but essentially you want to do one query that | |
// finds all friends within the list of users | |
$or: { friend_id : users } | |
}, function(results) { | |
// Then produce a map of the data in the way you want it: | |
if (err) return console.log("houston we got a problem."); | |
var parsed = results.map(function(r) { | |
return { | |
'fav': r.favorites, | |
'notes': r.notes, | |
'labels': r.labels, | |
'user': user, | |
'status':r.friend_status | |
}; | |
}); | |
callback(null, results) | |
}); | |
} | |
], | |
function(err, 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