Skip to content

Commit

Permalink
Tag delete api method
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh committed Aug 19, 2014
1 parent baa428e commit d24ae99
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/api/routes/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Module dependencies.
*/

var Check = require('../../../models/check');
var Tag = require('../../../models/tag');
var TagHourlyStat = require('../../../models/tagHourlyStat');
var CheckEvent = require('../../../models/checkEvent');
Expand Down Expand Up @@ -78,4 +79,16 @@ module.exports = function(app) {
});
});

app.delete('/tags/:name', loadTag, function(req, res, next) {
// Delete tag relation first in order to avoid magic respawn
Check.collection.update({ tags: req.tag.name }, { $pull: { tags: req.tag.name } }, { multi: true }, function(err) {
if (err) return next(err);
// Then, remove the tag
req.tag.remove(function(err2) {
if (err2) return next(err2);
res.end();
});
})
});

};

0 comments on commit d24ae99

Please sign in to comment.