From f826e18ff53fe355c5f412974bf1261039cd1325 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Wed, 25 Nov 2020 21:33:19 +0100 Subject: [PATCH] chore: remove "following" logic which is not used --- models/User.js | 21 --------------------- routes/api/profiles.js | 18 ------------------ routes/api/tracks.js | 11 +++-------- 3 files changed, 3 insertions(+), 47 deletions(-) diff --git a/models/User.js b/models/User.js index ce5943d..16efd55 100644 --- a/models/User.js +++ b/models/User.js @@ -24,7 +24,6 @@ const schema = new mongoose.Schema( }, bio: String, image: String, - following: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }], areTracksVisibleForAll: Boolean, hash: String, salt: String, @@ -83,28 +82,8 @@ class User extends mongoose.Model { username: this.username, bio: this.bio, image: this.image || 'https://static.productionready.io/images/smiley-cyrus.jpg', - following: user ? user.isFollowing(this._id) : false, }; } - - follow(id) { - if (this.following.indexOf(id) === -1) { - this.following.push(id); - } - - return this.save(); - } - - unfollow(id) { - this.following.remove(id); - return this.save(); - } - - isFollowing(id) { - return this.following.some(function (followId) { - return followId.toString() === id.toString(); - }); - } } mongoose.model(User, schema); diff --git a/routes/api/profiles.js b/routes/api/profiles.js index 7d435ee..d086595 100644 --- a/routes/api/profiles.js +++ b/routes/api/profiles.js @@ -28,22 +28,4 @@ router.get( }), ); -router.post( - '/:username/follow', - auth.required, - wrapRoute(async (req, res) => { - await req.user.follow(req.profile._id); - return res.json({ profile: req.profile.toProfileJSONFor(req.user) }); - }), -); - -router.delete( - '/:username/follow', - auth.required, - wrapRoute(async (req, res) => { - await req.user.unfollow(req.profile._id); - return res.json({ profile: req.profile.toProfileJSONFor(req.user) }); - }), -); - module.exports = router; diff --git a/routes/api/tracks.js b/routes/api/tracks.js index 2cdd642..735dffb 100644 --- a/routes/api/tracks.js +++ b/routes/api/tracks.js @@ -105,15 +105,10 @@ router.get( offset = req.query.offset; } - const showByUserIds = [req.user.id, ...(req.user.following || [])]; - + const query = { author: req.user.id }; const [tracks, tracksCount] = await Promise.all([ - Track.find({ author: { $in: showByUserIds } }) - .limit(Number(limit)) - .skip(Number(offset)) - .populate('author') - .exec(), - Track.countDocuments({ author: { $in: showByUserIds } }), + Track.find(query).limit(Number(limit)).skip(Number(offset)).populate('author').exec(), + Track.countDocuments(query), ]); return res.json({