From dbe4b1db178cea5aea9b58785790c05bcc9373b7 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Wed, 25 Nov 2020 15:58:26 +0100 Subject: [PATCH] chore: remove unused "favorite" track functionality --- models/User.js | 14 -------------- routes/api/tracks.js | 37 +------------------------------------ 2 files changed, 1 insertion(+), 50 deletions(-) diff --git a/models/User.js b/models/User.js index d8b4fde..ce5943d 100644 --- a/models/User.js +++ b/models/User.js @@ -24,7 +24,6 @@ const schema = new mongoose.Schema( }, bio: String, image: String, - favorites: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Track' }], following: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }], areTracksVisibleForAll: Boolean, hash: String, @@ -88,19 +87,6 @@ class User extends mongoose.Model { }; } - async favorite(id) { - if (this.favorites.indexOf(id) === -1) { - this.favorites.push(id); - } - - return await this.save(); - } - - async unfavorite(id) { - this.favorites.remove(id); - return await this.save(); - } - follow(id) { if (this.following.indexOf(id) === -1) { this.following.push(id); diff --git a/routes/api/tracks.js b/routes/api/tracks.js index 2b147b9..033fd5a 100644 --- a/routes/api/tracks.js +++ b/routes/api/tracks.js @@ -63,21 +63,12 @@ router.get( query.tagList = { $in: [req.query.tag] }; } - const [author, favoriter] = await Promise.all([ - req.query.author ? User.findOne({ username: req.query.author }) : null, - req.query.favorited ? User.findOne({ username: req.query.favorited }) : null, - ]); + const author = req.query.author ? await User.findOne({ username: req.query.author }) : null if (author) { query.author = author._id; } - if (favoriter) { - query._id = { $in: favoriter.favorites }; - } else if (req.query.favorited) { - query._id = { $in: [] }; - } - const [tracks, tracksCount] = await Promise.all([ Track.find(query).limit(Number(limit)).skip(Number(offset)).sort({ createdAt: 'desc' }).populate('author').exec(), Track.countDocuments(query).exec(), @@ -363,32 +354,6 @@ router.delete( }), ); -// Favorite an track -router.post( - '/:track/favorite', - auth.required, - wrapRoute(async (req, res) => { - const trackId = req.track._id; - - await req.user.favorite(trackId); - const track = await req.track.updateFavoriteCount(); - return res.json({ track: track.toJSONFor(req.user) }); - }), -); - -// Unfavorite an track -router.delete( - '/:track/favorite', - auth.required, - wrapRoute(async (req, res) => { - const trackId = req.track._id; - - await req.user.unfavorite(trackId); - const track = await req.track.updateFavoriteCount(); - return res.json({ track: track.toJSONFor(req.user) }); - }), -); - // return an track's comments router.get( '/:track/comments',