sanitize task when updating in v2

This commit is contained in:
Matteo Pagliazzi
2016-05-31 11:09:32 +02:00
parent b1a2632319
commit 6b214e4e3f
2 changed files with 15 additions and 2 deletions

View File

@@ -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);