SHARE
TWEET

Untitled

a guest Apr 26th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. router.route('/watchlist').get((req, res) => {
  2.   userSchema.User.findOne({
  3.     email: req.user.email
  4.   }, (err, user) => {
  5.     if(!user) {
  6.     } else {
  7.       if(!user.watchlist) {
  8.         res.send({ msg: "Watchlist empty", watchlist: [] });
  9.       } else {
  10.         res.send({ watchlist: user.watchlist });
  11.       }
  12.     }
  13.   });
  14. });
  15.  
  16. router.route('/watch/:ticker').post((req, res) => {
  17.   userSchema.User.findOne({
  18.     email: req.user.email
  19.   }, (err, user) => {
  20.     if(!user) {
  21.       console.log('User not found');
  22.     } else {
  23.       user.watchlist.push(req.params.ticker);
  24.       user.save();
  25.       res.send({ msg: req.params.ticker + " added to watchlist." });
  26.     }
  27.   });
  28. });
  29.  
  30. router.route('/watch/:ticker').delete((req, res) => {
  31.   userSchema.User.findOne({
  32.     email: req.user.email
  33.   }, (err, user) => {
  34.     if(!user) {
  35.       console.log('User not found');
  36.     } else {
  37.       user.watchlist.splice(req.params.ticker);
  38.       user.save();
  39.       res.send({ msg: req.params.ticker + " removed from watchlist"});
  40.     }
  41.   });
  42. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top