[#1977] [#1616] move sortTask to user.ops

This commit is contained in:
Tyler Renelle 2013-12-12 17:32:54 -07:00
parent dc63eff41d
commit caa2f26003
2 changed files with 2 additions and 16 deletions

View file

@ -55,8 +55,7 @@ habitrpg.directive('habitrpgSortable', ['User', function(User) {
var taskType = angular.element(ui.item[0]).scope().task.type + 's';
var startIndex = ui.item.data('startIndex');
var task = User.user[taskType][startIndex];
// FIXME - this is a really inconsistent way of API handling. we need to fix the batch-update route
User.log({op: 'sortTask', data: _.defaults({from: startIndex, to: ui.item.index()}, task)});
User.user.ops.sortTask({params:{id:task.id},query:{from:startIndex, to:ui.item.index()}});
}
});
}

View file

@ -153,21 +153,8 @@ api.deleteTask = function(req, res, next) {
*/
// api.updateTask // handled in Shared.ops
// api.addTask // handled in Shared.ops
api.sortTask = function(req, res, next) {
api.verifyTaskExists(req, res, function(){
var id = req.params.id;
var to = req.body.to, from = req.body.from, type = req.body.type;
var user = res.locals.user;
user[type+'s'].splice(to, 0, user[type+'s'].splice(from, 1)[0]);
user.save(function(err, saved) {
if (err) return res.json(500, {err: err});
return res.json(200, saved.toJSON()[type+'s']);
});
})
};
// api.sortTask // handled in Shared.ops #TODO updated api, mention in docs
/*
------------------------------------------------------------------------