habitica/common/script/ops/updateTask.js

21 lines
614 B
JavaScript
Raw Normal View History

2016-03-07 22:02:42 +00:00
import i18n from '../i18n';
import _ from 'lodash';
2016-03-08 16:45:14 +00:00
module.exports = function(user, req, cb) {
2016-03-07 22:02:42 +00:00
var ref, task;
2016-03-08 16:45:14 +00:00
if (!(task = user.tasks[(ref = req.params) != null ? ref.id : void 0])) {
return typeof cb === "function" ? cb({
2016-03-07 22:02:42 +00:00
code: 404,
message: i18n.t('messageTaskNotFound', req.language)
}) : void 0;
}
_.merge(task, _.omit(req.body, ['checklist', 'id', 'type']));
if (req.body.checklist) {
task.checklist = req.body.checklist;
}
2016-03-08 16:45:14 +00:00
if (typeof task.markModified === "function") {
2016-03-07 22:02:42 +00:00
task.markModified('tags');
}
2016-03-08 16:45:14 +00:00
return typeof cb === "function" ? cb(null, task) : void 0;
2016-03-07 22:02:42 +00:00
};