mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
port updateTask, addTask, clearCompleted, taskDefaults, uuid
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function(user, req, cb) {
|
||||
var ref, task;
|
||||
if (!(task = user.tasks[(ref = req.params) != null ? ref.id : void 0])) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 404,
|
||||
message: i18n.t('messageTaskNotFound', req.language)
|
||||
}) : void 0;
|
||||
}
|
||||
_.merge(task, _.omit(req.body, ['checklist', 'reminders', 'id', 'type']));
|
||||
if (req.body.checklist) {
|
||||
task.checklist = req.body.checklist;
|
||||
}
|
||||
// From server pass task.toObject() not the task document directly
|
||||
module.exports = function updateTask (task, req = {}) {
|
||||
// If reminders are updated -> replace the original ones
|
||||
if (req.body.reminders) {
|
||||
task.reminders = req.body.reminders;
|
||||
delete req.body.reminders;
|
||||
}
|
||||
if (typeof task.markModified === "function") {
|
||||
task.markModified('tags');
|
||||
|
||||
// If checklist is updated -> replace the original one
|
||||
if (req.body.checklist) {
|
||||
task.checklist = req.body.checklist;
|
||||
delete req.body.checklist;
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, task) : void 0;
|
||||
|
||||
// If tags are updated -> replace the original ones
|
||||
if (req.body.tags) {
|
||||
task.tags = req.body.tags;
|
||||
delete req.body.tags;
|
||||
}
|
||||
|
||||
_.merge(task, _.omit(req.body, ['_id', 'id', 'type']));
|
||||
|
||||
return task;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user