mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 15:38:59 +00:00
fix #1611, @lefnire added a migration for deleted tags, this time it should not delete all of them ;)
This commit is contained in:
parent
e722a064c8
commit
8e5edbbef8
2 changed files with 17 additions and 0 deletions
13
migrations/20131122_deleted_tags.js
Normal file
13
migrations/20131122_deleted_tags.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Cleanup broken tags
|
||||||
|
// -------------------------
|
||||||
|
db.users.find().forEach(function(user){
|
||||||
|
var tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards);
|
||||||
|
|
||||||
|
_.each(tasks, function(task){
|
||||||
|
_.each(task.tags, function(value, key){ //value is true, key is tag.id
|
||||||
|
if (!_.find(user.tags,{id:key})) delete task.tags[key];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
db.users.update({_id:user._id}, user);
|
||||||
|
});
|
||||||
|
|
@ -471,6 +471,10 @@ api.deleteTag = function(req, res){
|
||||||
delete task.tags[tag.id];
|
delete task.tags[tag.id];
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
user.markModified('habits');
|
||||||
|
user.markModified('dailys');
|
||||||
|
user.markModified('todos');
|
||||||
|
user.markModified('rewards');
|
||||||
user.save(function(err,saved){
|
user.save(function(err,saved){
|
||||||
if (err) return res.json(500, {err: err});
|
if (err) return res.json(500, {err: err});
|
||||||
res.send(204);
|
res.send(204);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue