chore: remove "following" logic which is not used

This commit is contained in:
Paul Bienkowski 2020-11-25 21:33:19 +01:00
parent 80b2169b15
commit f826e18ff5
3 changed files with 3 additions and 47 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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({