diff --git a/server/models/project.js b/server/models/project.js index 757cbf5..a70c2a2 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -146,7 +146,7 @@ ProjectSchema.statics.findProjectByUserId = function (userId, idproj) { } else { return Project.findOne({ 'userId': userId, - '_id': ObjectId(idproj), + '_id': idproj, }); } }; @@ -156,6 +156,7 @@ ProjectSchema.statics.findAllProjByUserId = async function (userId) { var Project = this; return Project.aggregate([ + { $match: { $or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }] } }, { $graphLookup: { from: "projects", diff --git a/server/models/todo.js b/server/models/todo.js index b6ae167..17c44dc 100644 --- a/server/models/todo.js +++ b/server/models/todo.js @@ -140,26 +140,17 @@ function getQueryTodo(filterMatchBefore = {}, userId) { return query; } -TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') { +TodoSchema.statics.findAllByUserIdAndCat = function (userId) { var Todo = this; - if (category === '') { + const query = getQueryTodo({}, userId); - const query = getQueryTodo({}, userId); - - return Todo.aggregate(query) - .then(ris => { - // console.log('ris TODO:', ris); - //return tools.mapSort(ris) - return ris - }); - - } else { - return Todo.find({ - 'userId': userId, - 'category': category, + return Todo.aggregate(query) + .then(ris => { + // console.log('ris TODO:', ris); + //return tools.mapSort(ris) + return ris }); - } }; TodoSchema.statics.getArrIdParentInTable = function (userId) { @@ -216,7 +207,7 @@ TodoSchema.statics.getAllTodo = async function (userId) { obj.arrcategories = await Todo.getArrIdParentInTable(userId); - console.log('obj.arrcategories', obj.arrcategories); + // console.log('obj.arrcategories', obj.arrcategories); let arrtodos = []; if (obj.arrcategories.length > 0) { @@ -226,7 +217,10 @@ TodoSchema.statics.getAllTodo = async function (userId) { if (arrfiltrato.length > 0) { const arrmap = tools.mapSort(arrfiltrato); arrtodos.push(arrmap); - console.log('AGGIUNGI RECORDS TODO! cat: ', mycat, 'da aggiungere:', arrfiltrato.length, 'attuali', arrtodos.length); + // console.log('AGGIUNGI RECORDS TODO! cat: ', mycat, 'da aggiungere:', arrfiltrato.length, 'attuali', arrtodos.length); + // console.log(arrtodos) + } else { + arrtodos.push([]); } } } @@ -234,12 +228,33 @@ TodoSchema.statics.getAllTodo = async function (userId) { obj.arrtodos = arrtodos; - console.log('obj.arrtodos', obj.arrtodos); + // console.log('obj.arrtodos:'); + // logtodo(obj.arrtodos); return obj; }; +function getelem(item) { + return item.descr + ' ' + item.category; +} + +function logtodo(myarr) { + console.log(getarrlog(myarr)); +} + +function getarrlog(myarr) { + let mystr = ""; + for (const indcat in myarr){ + mystr += indcat + ': \n'; + for (const indelem in myarr[indcat]) { + mystr += ' [' + indelem + '] ' + getelem(myarr[indcat][indelem]) + '\n'; + } + } + + return mystr +} + class CalcTodo { constructor(phase) { diff --git a/server/router/projects_router.js b/server/router/projects_router.js index ec45037..162c704 100644 --- a/server/router/projects_router.js +++ b/server/router/projects_router.js @@ -134,6 +134,8 @@ router.get('/:userId', authenticate, (req, res) => { if (!!objprojects.arrproj) tools.mylog('projects', objprojects.arrproj.length); + // console.log(objprojects.arrproj); + return objprojects }).then((objprojects) => { diff --git a/server/tools/general.js b/server/tools/general.js index b3788c3..1b31ccf 100644 --- a/server/tools/general.js +++ b/server/tools/general.js @@ -235,7 +235,7 @@ module.exports = { if (linkedList.length > sortedList.length) { // If are not in the list, I'll put at the bottom of the list - console.log('ATTENZIONE !!! ', sortedList.length, linkedList.length); + // console.log('ATTENZIONE !!! ', sortedList.length, linkedList.length); for (const itemlinked of linkedList) { const elemtrov = sortedList.find((item) => item._id === itemlinked._id); if (elemtrov === undefined) {