Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.route('/api/favorites')
- .get(validation.verifyToken, async (req, resp) => {
- const apikey = validation.getApiKey(req.headers['authorization']);
- if (!apikey) {
- resp.status(403).send("Please log in to view this page");
- } else {
- let movieIDList = []
- let favorites = []
- await User.findOne({ apikey }, (err, data) => {
- if (err) {
- console.log(err);
- resp.json("Unable to find user");
- } else {
- if (data.favorites !== null) {
- movieIDList = [...data.favorites];
- }
- }
- });
- await Movie.find({ id: [...movieIDList] }, (err, data) => {
- if (err) {
- } else {
- let formatted = data.map(cur => {
- return {
- id: cur.id,
- title: cur.title,
- poster: cur.poster
- }
- })
- resp.json({ favorites: formatted })
- }
- })
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement