mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
sanitize task when updating in v2
This commit is contained in:
@@ -867,7 +867,20 @@ api.updateTask = function(req, res, next) {
|
||||
if(!task) return res.status(404).json({err: 'Task not found.'})
|
||||
|
||||
try {
|
||||
_.assign(task, shared.ops.updateTask(task.toObject(), req)[0]);
|
||||
// we have to convert task to an object because otherwise things don't get merged correctly. Bad for performances?
|
||||
let [updatedTaskObj] = shared.ops.updateTask(task.toObject(), req);
|
||||
|
||||
// Sanitize differently user tasks linked to a challenge
|
||||
let sanitizedObj;
|
||||
|
||||
if (task.userId && task.challenge && task.challenge.id) {
|
||||
sanitizedObj = Tasks.Task.sanitizeUserChallengeTask(updatedTaskObj);
|
||||
} else {
|
||||
sanitizedObj = Tasks.Task.sanitize(updatedTaskObj);
|
||||
}
|
||||
|
||||
_.assign(task, sanitizedObj);
|
||||
|
||||
task.save(function(err, task){
|
||||
if(err) return next(err);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ let discriminatorOptions = {
|
||||
};
|
||||
let subDiscriminatorOptions = _.defaults(_.cloneDeep(discriminatorOptions), {
|
||||
_id: false,
|
||||
minimize: false,
|
||||
minimize: false, // So empty objects are returned
|
||||
});
|
||||
|
||||
export let tasksTypes = ['habit', 'daily', 'todo', 'reward'];
|
||||
|
||||
Reference in New Issue
Block a user