chore: remove "following" logic which is not used
This commit is contained in:
parent
80b2169b15
commit
f826e18ff5
|
@ -24,7 +24,6 @@ const schema = new mongoose.Schema(
|
||||||
},
|
},
|
||||||
bio: String,
|
bio: String,
|
||||||
image: String,
|
image: String,
|
||||||
following: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
|
|
||||||
areTracksVisibleForAll: Boolean,
|
areTracksVisibleForAll: Boolean,
|
||||||
hash: String,
|
hash: String,
|
||||||
salt: String,
|
salt: String,
|
||||||
|
@ -83,28 +82,8 @@ class User extends mongoose.Model {
|
||||||
username: this.username,
|
username: this.username,
|
||||||
bio: this.bio,
|
bio: this.bio,
|
||||||
image: this.image || 'https://static.productionready.io/images/smiley-cyrus.jpg',
|
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);
|
mongoose.model(User, schema);
|
||||||
|
|
|
@ -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;
|
module.exports = router;
|
||||||
|
|
|
@ -105,15 +105,10 @@ router.get(
|
||||||
offset = req.query.offset;
|
offset = req.query.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
const showByUserIds = [req.user.id, ...(req.user.following || [])];
|
const query = { author: req.user.id };
|
||||||
|
|
||||||
const [tracks, tracksCount] = await Promise.all([
|
const [tracks, tracksCount] = await Promise.all([
|
||||||
Track.find({ author: { $in: showByUserIds } })
|
Track.find(query).limit(Number(limit)).skip(Number(offset)).populate('author').exec(),
|
||||||
.limit(Number(limit))
|
Track.countDocuments(query),
|
||||||
.skip(Number(offset))
|
|
||||||
.populate('author')
|
|
||||||
.exec(),
|
|
||||||
Track.countDocuments({ author: { $in: showByUserIds } }),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
|
|
Loading…
Reference in a new issue