mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-03 18:51:09 +01:00
feat(torrent): remove all complete warning of torrent when the torrent H&R status to false and when the torrent be deleted
This commit is contained in:
@@ -14,6 +14,7 @@ var path = require('path'),
|
||||
Subtitle = mongoose.model('Subtitle'),
|
||||
Thumb = mongoose.model('Thumb'),
|
||||
Torrent = mongoose.model('Torrent'),
|
||||
Complete = mongoose.model('Complete'),
|
||||
Forum = mongoose.model('Forum'),
|
||||
Topic = mongoose.model('Topic'),
|
||||
fs = require('fs'),
|
||||
@@ -503,13 +504,33 @@ exports.toggleHnRStatus = function (req, res) {
|
||||
});
|
||||
} else {
|
||||
res.json(torrent);
|
||||
|
||||
//remove the complete data and update user`s warning number when the H&R prop to false
|
||||
removeTorrentHnRWarning(torrent._id);
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: remove the complete data and update user`s warning number when the H&R prop to false
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* removeTorrentHnRWarning
|
||||
* @param torrent
|
||||
*/
|
||||
function removeTorrentHnRWarning(tid) {
|
||||
Complete.find({
|
||||
torrent: tid
|
||||
})
|
||||
.populate('user')
|
||||
.exec(function (err, cs) {
|
||||
if (!err && cs) {
|
||||
cs.forEach(function (c) {
|
||||
if (c.hnr_warning) {
|
||||
c.removeHnRWarning(c.user);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* thumbsUp
|
||||
* @param req
|
||||
@@ -733,7 +754,11 @@ exports.delete = function (req, res) {
|
||||
torrent: torrent._id
|
||||
});
|
||||
|
||||
//TODO: remove the complete data and update user`s warning number if the torrent has H&R prop
|
||||
//remove the complete data and update user`s warning number if the torrent has H&R prop
|
||||
removeTorrentHnRWarning(torrent._id);
|
||||
Complete.remove({
|
||||
torrent: torrent._id
|
||||
});
|
||||
|
||||
torrent.remove(function (err) {
|
||||
if (err) {
|
||||
|
||||
@@ -135,6 +135,23 @@ CompleteSchema.methods.countHnRWarning = function (u) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* removeHnRWarning
|
||||
* remove H&R warning
|
||||
*/
|
||||
CompleteSchema.methods.removeHnRWarning = function (u) {
|
||||
if (this.hnr_warning) {
|
||||
this.update({
|
||||
$set: {hnr_warning: false}
|
||||
}).exec();
|
||||
|
||||
//update user warning numbers
|
||||
u.update({
|
||||
$inc: {hnr_warning: -1}
|
||||
}).exec();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
CompleteSchema.index({user: -1, createdAt: -1});
|
||||
CompleteSchema.index({torrent: 1, createdAt: -1});
|
||||
|
||||
Reference in New Issue
Block a user