deleting a user will delete topic tags too

This commit is contained in:
barisusakli
2014-05-21 19:39:10 -04:00
parent df73ceaeb7
commit d8fd29581e
2 changed files with 27 additions and 24 deletions

View File

@@ -57,23 +57,23 @@ module.exports = function(Topics) {
} }
Topics.updateTags = function(tid, tags) { Topics.updateTags = function(tid, tags) {
async.parallel({ Topics.getTopicField(tid, 'timestamp', function(err, timestamp) {
timestamp: function(next) {
Topics.getTopicField(tid, 'timestamp', next);
},
currentTags: function(next) {
Topics.getTopicTags(tid, next);
}
}, function(err, results) {
removeTopicTags(tid, results.currentTags, function(err) {
if (!err) { if (!err) {
Topics.createTags(tags, tid, results.timestamp); Topics.deleteTopicTags(tid, function(err) {
if (!err) {
Topics.createTags(tags, tid, timestamp);
} }
}); });
}
}); });
}; };
function removeTopicTags(tid, tags, callback) { Topics.deleteTopicTags = function(tid, callback) {
Topics.getTopicTags(tid, function(err, tags) {
if (err) {
return callback(err);
}
async.parallel([ async.parallel([
function(next) { function(next) {
db.delete('topic:' + tid + ':tags', next); db.delete('topic:' + tid + ':tags', next);
@@ -84,7 +84,8 @@ module.exports = function(Topics) {
}, next); }, next);
} }
], callback); ], callback);
} });
};
Topics.searchTags = function(query, callback) { Topics.searchTags = function(query, callback) {
if (!query || query.length === 0) { if (!query || query.length === 0) {

View File

@@ -153,7 +153,6 @@ module.exports = function(User) {
} }
function deleteTopic(tid, callback) { function deleteTopic(tid, callback) {
async.parallel([ async.parallel([
function(next) { function(next) {
db.delete('tid:' + tid + ':followers', next); db.delete('tid:' + tid + ':followers', next);
@@ -175,6 +174,9 @@ module.exports = function(User) {
}, },
function(next) { function(next) {
deleteTopicFromCategory(tid, next); deleteTopicFromCategory(tid, next);
},
function(next) {
topics.deleteTopicTags(tid, next);
} }
], function(err) { ], function(err) {
if (err) { if (err) {