Updated Project calculation for hours and progress.
This commit is contained in:
@@ -10,6 +10,7 @@ var { authenticate } = require('../middleware/authenticate');
|
||||
// var mongoose = require('mongoose');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
const { Todo } = require('./../models/todo');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
@@ -65,7 +66,6 @@ router.post('/', authenticate, (req, res) => {
|
||||
});
|
||||
|
||||
|
||||
|
||||
router.patch('/:id', authenticate, (req, res) => {
|
||||
var id = req.params.id;
|
||||
var body = _.pick(req.body, tools.allfieldProject());
|
||||
@@ -118,16 +118,21 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
|
||||
// Extract all the projects of the userId only
|
||||
// Project.findAllByUserIdAndCat(userId, category).then((projects) => {
|
||||
Project.getAllProjects(userId).then((objprojects) => {
|
||||
return Project.getAllProjects(userId).then((objprojects) => {
|
||||
tools.mylog('projects', objprojects.arrproj.length);
|
||||
|
||||
objout = calcProjects(objprojects);
|
||||
return objprojects
|
||||
|
||||
res.send({ projects: objout });
|
||||
}).then((objprojects) => {
|
||||
// tools.mylog('objprojects', objprojects);
|
||||
|
||||
tools.mylog('objout', objout);
|
||||
|
||||
// res.send({ projects: objprojects.arrproj, categories: objprojects.arrcategories });
|
||||
// if (tools.EXECUTE_CALCPROJ) {
|
||||
// return calcProjects('', objprojects).then(objout => {
|
||||
// res.send({ projects: objprojects.arrproj });
|
||||
// });
|
||||
// } else {
|
||||
res.send({ projects: objprojects.arrproj });
|
||||
// }
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
res.status(400).send(e);
|
||||
@@ -135,20 +140,28 @@ router.get('/:userId', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
function calcProjects(obj) {
|
||||
// USATO SOLO LE PRIME VOLTE! O A RICHIESTA!
|
||||
async function calcProjects(userId, obj) {
|
||||
|
||||
let myarr = tools.jsonCopy(obj.arrproj);
|
||||
// let myarr = tools.jsonCopy(obj.arrproj);
|
||||
let myarr = [...obj.arrproj];
|
||||
|
||||
for (const indrec in myarr) {
|
||||
// Calculate the Progression of the Project
|
||||
if (myarr.length > 0) {
|
||||
let promiseChain = Promise.resolve();
|
||||
|
||||
// Find the todos for this project
|
||||
|
||||
// sum the progression
|
||||
|
||||
myarr[indrec].progressCalc = Math.round(Math.random() * 100);
|
||||
for (const rec of myarr) {
|
||||
promiseChain = promiseChain.then(() => {
|
||||
// Find the todos for this project
|
||||
// Calculate the Progression of the Project // sum the progression
|
||||
return Todo.calculateTreeTodo(userId, rec._id, false, rec._id, false)
|
||||
})
|
||||
}
|
||||
return promiseChain
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
return myarr
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user