Updated Project calculation for hours and progress.
This commit is contained in:
@@ -5,6 +5,8 @@ const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
@@ -66,12 +68,11 @@ router.post('/', authenticate, (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
|
||||
router.patch('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
var body = _.pick(req.body, tools.allfieldTodo());
|
||||
|
||||
tools.mylogshow('PATCH TODO: ', id)
|
||||
tools.mylogshow('PATCH TODO: ', id);
|
||||
|
||||
if (!ObjectID.isValid(id)) {
|
||||
tools.mylog('ERROR: id not VALID', id);
|
||||
@@ -79,26 +80,31 @@ router.patch('/:id', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
|
||||
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.findByIdAndUpdate(id, { $set: body }, { new: true }).then((todo) => {
|
||||
if (!todo) {
|
||||
tools.mylogshow(' TODO NOT FOUND !: id:', id, 'body: ', body);
|
||||
return res.status(404).send();
|
||||
}
|
||||
let level = 0;
|
||||
return Todo.calculateTreeTodo(todo.userId, todo.category, true, todo.category, false)
|
||||
.then(objdatacalc => {
|
||||
tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
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.modified = false;
|
||||
|
||||
todo.modified = false;
|
||||
tools.mylog('PATCH ', todo.descr, todo._id);
|
||||
|
||||
tools.mylog('PATCH ', todo.descr, todo._id);
|
||||
res.send({ todo, objdatacalc });
|
||||
});
|
||||
|
||||
res.send({ todo });
|
||||
}).catch((e) => {
|
||||
}).catch((e) => {
|
||||
tools.mylogserr('Error patch TODO: ', e);
|
||||
res.status(400).send();
|
||||
})
|
||||
@@ -121,7 +127,6 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
// Todo.findAllByUserIdAndCat(userId, category).then((todos) => {
|
||||
Todo.getAllTodo(userId).then((objtodos) => {
|
||||
|
||||
tools.mylog('todos', objtodos.arrtodos.length);
|
||||
|
||||
Reference in New Issue
Block a user