@@ -1,25 +1,23 @@
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
|
||||
// From server pass task.toObject() not the task document directly
|
||||
module.exports = function updateTask (task, req = {}) {
|
||||
let body = req.body || {};
|
||||
|
||||
// If reminders are updated -> replace the original ones
|
||||
if (body.reminders) {
|
||||
task.reminders = body.reminders;
|
||||
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;
|
||||
}
|
||||
|
||||
// If checklist is updated -> replace the original one
|
||||
if (body.checklist) {
|
||||
task.checklist = body.checklist;
|
||||
_.merge(task, _.omit(req.body, ['checklist', 'reminders', 'id', 'type']));
|
||||
if (req.body.checklist) {
|
||||
task.checklist = req.body.checklist;
|
||||
}
|
||||
|
||||
// If tags are updated -> replace the original ones
|
||||
if (body.tags) {
|
||||
task.tags = body.tags;
|
||||
if (req.body.reminders) {
|
||||
task.reminders = req.body.reminders;
|
||||
}
|
||||
|
||||
_.merge(task, _.omit(body, ['_id', 'id', 'type', 'reminders', 'checklist', 'tags']));
|
||||
|
||||
return [task];
|
||||
if (typeof task.markModified === "function") {
|
||||
task.markModified('tags');
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, task) : void 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user