Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.route('/api/favorites')
  2.         .get(validation.verifyToken, async (req, resp) => {
  3.             const apikey = validation.getApiKey(req.headers['authorization']);
  4.             if (!apikey) {
  5.                 resp.status(403).send("Please log in to view this page");
  6.             } else {
  7.                 let movieIDList = []
  8.                 let favorites = []
  9.  
  10.                 await User.findOne({ apikey }, (err, data) => {
  11.                     if (err) {
  12.                         console.log(err);
  13.                         resp.json("Unable to find user");
  14.                     } else {
  15.                         if (data.favorites !== null) {
  16.                             movieIDList = [...data.favorites];
  17.                         }
  18.                     }
  19.                 });
  20.  
  21.                 await Movie.find({ id: [...movieIDList] }, (err, data) => {
  22.                     if (err) {
  23.  
  24.                     } else {
  25.                         let formatted = data.map(cur => {
  26.                             return {
  27.                                 id: cur.id,
  28.                                 title: cur.title,
  29.                                 poster: cur.poster
  30.                             }
  31.                         })
  32.                         resp.json({ favorites: formatted })
  33.                     }
  34.                 })
  35.             }
  36.         })
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement