Files
habitica/website/common/script/ops/updateTask.js
Keith Holliday 1082359f2c Repeatables fixes (#8538)
* Prevented watch functions from being called when task._edit is removed

* Added start date support on the UI task summary

* Fixed setting of monthly and calculations

* Fixed linting issues

* Added check for existence

* Added existence check

* Ensured correct start date is used on update

* Hid repeat options from anything not a daily

* Added missing locales

* Moved repeatables out of advance options
2017-03-08 16:48:30 -07:00

36 lines
894 B
JavaScript

import merge from 'lodash/merge';
import omit from 'lodash/omit';
// 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;
}
// If checklist is updated -> replace the original one
if (body.checklist) {
task.checklist = body.checklist;
}
// If tags are updated -> replace the original ones
if (body.tags) {
task.tags = body.tags;
}
merge(task, omit(body, ['_id', 'id', 'type', 'reminders', 'checklist', 'tags']));
// Ensure arrays are emptied
if (body.daysOfMonth && body.daysOfMonth.length === 0) {
task.daysOfMonth = [];
}
if (body.weeksOfMonth && body.weeksOfMonth.length === 0) {
task.weeksOfMonth = [];
}
return [task];
};