mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-10 17:51:27 +02:00
feat(follow): follow & unfollow in userinfo page
This commit is contained in:
@@ -144,7 +144,7 @@ exports.changeProfilePicture = function (req, res) {
|
||||
if (existingImageUrl !== User.schema.path('profileImageURL').defaultValue) {
|
||||
if (useS3Storage) {
|
||||
try {
|
||||
var { region, bucket, key } = amazonS3URI(existingImageUrl);
|
||||
var {region, bucket, key} = amazonS3URI(existingImageUrl);
|
||||
var params = {
|
||||
Bucket: config.aws.s3.bucket,
|
||||
Key: key
|
||||
@@ -292,3 +292,39 @@ exports.unIdle = function (req, res, next) {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* followTo
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
exports.followTo = function (req, res) {
|
||||
var user = req.user;
|
||||
var toUser = req.model;
|
||||
|
||||
toUser.followers.push(user._id);
|
||||
toUser.save();
|
||||
|
||||
user.following.push(toUser._id);
|
||||
user.save(function (err) {
|
||||
res.json(user);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* unFollowTo
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
exports.unFollowTo = function (req, res) {
|
||||
var user = req.user;
|
||||
var toUser = req.model;
|
||||
|
||||
toUser.followers.pull(user._id);
|
||||
toUser.save();
|
||||
|
||||
user.following.pull(toUser._id);
|
||||
user.save(function (err) {
|
||||
res.json(user);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -14,6 +14,8 @@ module.exports = function (app) {
|
||||
app.route('/api/users/warningNumber').get(users.warningNumber);
|
||||
app.route('/api/users/picture').post(users.changeProfilePicture);
|
||||
app.route('/api/users/signature').post(users.changeSignature);
|
||||
app.route('/api/users/followTo/:userId').post(users.followTo);
|
||||
app.route('/api/users/unFollowTo/:userId').post(users.unFollowTo);
|
||||
|
||||
// Finish by binding the user middleware
|
||||
app.param('userId', users.userByID);
|
||||
|
||||
Reference in New Issue
Block a user