This commit is contained in:
Paolo Arena
2021-02-18 12:19:35 +01:00
parent 88ae9af12c
commit 14a3292da2
22 changed files with 233 additions and 122 deletions

View File

@@ -81,34 +81,43 @@ router.patch('/:id', authenticate, (req, res) => {
return res.status(404).send();
}
Todo.findByIdAndUpdate(id, { $set: body }, { new: true })
.then((todo) => {
if (!todo) {
tools.mylogshow(' TODO NOT FOUND !: id:', id, 'body: ', body);
return res.status(404).send();
Todo.findById(id)
.then((todorec) => {
if (todorec) {
// Esiste, pertanto gli tolgo l'UserId generato in precedenza
delete body["userId"];
}
let level = 0;
return Todo.calculateTreeTodo(todo.phase, todo.userId, todo.category, true, todo.category, false)
.then(objdatacalc => {
// tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
if (todo.userId !== String(req.user._id)) {
// I'm trying to write something not mine!
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
Todo.findByIdAndUpdate(id, { $set: body }, { new: true })
.then((todo) => {
if (!todo) {
tools.mylogshow(' TODO NOT FOUND !: id:', id, 'body: ', body);
return res.status(404).send();
}
todo.modified = false;
let level = 0;
return Todo.calculateTreeTodo(todo.phase, todo.userId, todo.category, true, todo.category, false)
.then(objdatacalc => {
// tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
// tools.mylog('PATCH ', todo.descr, todo._id);
if (todo.userId !== String(req.user._id) && project.privacywrite === server_constants.Privacy.onlyme) {
// I'm trying to write something not mine!
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
}
res.send({ todo, objdatacalc });
});
todo.modified = false;
}).catch((e) => {
tools.mylogserr('Error patch TODO: ', e);
res.status(400).send();
})
// tools.mylog('PATCH ', todo.descr, todo._id);
res.send({ todo, objdatacalc });
});
}).catch((e) => {
tools.mylogserr('Error patch TODO: ', e);
res.status(400).send();
})
})
});