chore: remove unused "favorite" track functionality

This commit is contained in:
Paul Bienkowski 2020-11-25 15:58:26 +01:00
parent b75ba42969
commit dbe4b1db17
2 changed files with 1 additions and 50 deletions

View file

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

View file

@ -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',