0

so I am trying to search through the search results and see who already exists in the friendRequest array of the user searching. If they exist then I want to change the button that displays for the user to Contact requested and disable it.

Here is my code on the route file:

exports.searchPost = function(req, res, err) {
  User.find({$or:[
      {firstName: req.body.firstName},
      {lastName: req.body.lastName},
      {email: req.body.email},
      {phone: req.body.phone}]
  }, function(err, users, userAdd) {
    if(err) {

      return res.render('searchError', {title: 'Weblio'});
    } else {

      if(req.body.firstName=== '' && req.body.lastName==='' && req.body.email==='' && req.body.phone=== '') {
        //maybe  a diff page saying that is not a valid search page
        return res.render('searchError', {title: 'Weblio'});
      } else {
        console.log('addman');
        console.log(userAdd);
        console.log(users);
        for(x in users) {

          User.findById(req.signedCookies.userid,
            {friendRequest: x.id}
          if(x.id === true ) {
            console.log('addman1');
            return userAdd = false;
          } else {
            console.log('addman2');
            return userAdd = true;
          }

        });
        console.log(x);
      }
      console.log(userAdd);
      console.log(users);
      //can use this loop if want to serve the info as oppose to doing it in jade, just change users to uuser
      /*var i = 0;
      var uuser = [];
      for(i=0; i < users.length; i++) { 

        uuser.push(users[i].firstName + ' ' +  users[i].lastName);
      };
      */
      //console.log(i);
      return res.render('searchResults', {title: 'Weblio',
        usersFound: users,
        userAdded: userAdd
      });
    }
  }
});
};

Here is the jade file:

extends layout
block content   
    div
    legend Search Results
    div#userResults
    for user in usersFound 
        a(href='/user/#{user.id}')
            p #{user.firstName} #{user.lastName}
        - if(userAdded === false)
            button.addContact(data-user=user.id) Add Contact
        - else
            button.addContact(data-user=user.id, 'disabled'='disabled') Contact Requested
xxx
  • 1,153
  • 1
  • 11
  • 23
Lion789
  • 4,402
  • 12
  • 58
  • 96
  • 1
    Start using more `console.log` and dump everything to see what's being returned. – OneOfOne Jul 19 '13 at 20:41
  • Ok does anything look wrong though? – Lion789 Jul 20 '13 at 21:50
  • Not at the first look, that's why I said try to console.log a lot, start with `console.log(req.body)` and `users` – OneOfOne Jul 20 '13 at 23:42
  • Ok updated the code above, but userAdd shows up as undefined, users actually shows up the search results – Lion789 Jul 21 '13 at 03:56
  • You're passing a server-side function to the template? do you have something enabled that'd allow doing that? – OneOfOne Jul 21 '13 at 21:31
  • Yeah, I have jade and js pulling data from what is being rendered from node on the server side... – Lion789 Jul 22 '13 at 00:56
  • 1
    I actually kind of figured it out but now am having a different problem... http://stackoverflow.com/questions/17795437/async-series-responds-with-false-when-it-should-be-true – Lion789 Jul 22 '13 at 19:07

0 Answers0