From cadf2ef86af3a904487cbf2eddd3851d3f86243b Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Sat, 30 Mar 2019 02:58:19 +0100 Subject: [PATCH] - added fields: longdescr, hoursworked, hoursplanned --- server/models/project.js | 35 ++++++++++++++++++-------------- server/router/projects_router.js | 4 ++-- server/tools/general.js | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/server/models/project.js b/server/models/project.js index 1e27061..406a00d 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -24,6 +24,18 @@ var ProjectSchema = new mongoose.Schema({ descr: { type: String, }, + longdescr: { + type: String, + }, + hoursplanned: { + type: Number, + }, + hoursworked: { + type: Number, + }, + id_parent: { + type: String, + }, priority: { type: Number, }, @@ -65,7 +77,7 @@ ProjectSchema.methods.toJSON = function () { // console.log(projObject); - return _.pick(projObject, tools.allfieldTodoWithId()); + return _.pick(projObject, tools.allfieldProjectWithId()); }; @@ -78,22 +90,15 @@ ProjectSchema.statics.findByUserIdAndCat = function (userId, category) { }); }; -ProjectSchema.statics.findAllByUserIdAndCat = function (userId, category = '') { +ProjectSchema.statics.findAllByUserId = function (userId) { var Project = this; - if (category === '') { - return Project.find({ - 'userId': userId, - }).then(ris => { - return tools.mapSort(ris) - }) + return Project.find({ + 'userId': userId, + }).then(ris => { + return ris + }) - } else { - return Project.find({ - 'userId': userId, - 'category': category, - }); - } }; ProjectSchema.statics.getArrCategoryInTable = function (userId) { @@ -111,7 +116,7 @@ ProjectSchema.statics.getAllProjects = async function (userId) { let obj = []; - obj.arrproj = await Project.findAllByUserIdAndCat(userId); + obj.arrproj = await Project.findAllByUserId(userId); return obj; diff --git a/server/router/projects_router.js b/server/router/projects_router.js index bc81348..931a2cf 100644 --- a/server/router/projects_router.js +++ b/server/router/projects_router.js @@ -79,7 +79,7 @@ router.patch('/:id', authenticate, (req, res) => { Project.findByIdAndUpdate(id, { $set: body }, { new: true }).then((project) => { - tools.mylogshow(' PROJECT TO MODIFY: ', project.descr, project.expiring_at); + tools.mylogshow(' PROJECT TO MODIFY: ', project.descr, body); if (!project) { return res.status(404).send(); } @@ -146,7 +146,7 @@ function calcProjects(obj) { // sum the progression - myarr[indrec].progressCalc = 1; + myarr[indrec].progressCalc = Math.round(Math.random() * 100); } return myarr diff --git a/server/tools/general.js b/server/tools/general.js index 14ce73b..953b8b8 100644 --- a/server/tools/general.js +++ b/server/tools/general.js @@ -59,7 +59,7 @@ module.exports = { // #TODO Projects++ Add fields ... allfieldProject: function () { - return ['userId', 'pos', 'descr', 'priority', 'completed', 'created_at', 'modify_at', + return ['userId', 'pos', 'id_parent', 'descr', 'longdescr', 'hoursplanned', 'hoursworked', 'priority', 'completed', 'created_at', 'modify_at', 'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'progressCalc', 'modified'] },