End "project and Todos": what could modify or readonly.

This commit is contained in:
Paolo Arena
2019-04-22 01:43:58 +02:00
parent e0e48f7eb2
commit f3964b0ff0
4 changed files with 39 additions and 21 deletions

View File

@@ -146,7 +146,7 @@ ProjectSchema.statics.findProjectByUserId = function (userId, idproj) {
} else { } else {
return Project.findOne({ return Project.findOne({
'userId': userId, 'userId': userId,
'_id': ObjectId(idproj), '_id': idproj,
}); });
} }
}; };
@@ -156,6 +156,7 @@ ProjectSchema.statics.findAllProjByUserId = async function (userId) {
var Project = this; var Project = this;
return Project.aggregate([ return Project.aggregate([
{ $match: { $or: [{ privacyread: server_constants.Privacy.all }, { userId: userId }] } },
{ {
$graphLookup: { $graphLookup: {
from: "projects", from: "projects",

View File

@@ -140,26 +140,17 @@ function getQueryTodo(filterMatchBefore = {}, userId) {
return query; return query;
} }
TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') { TodoSchema.statics.findAllByUserIdAndCat = function (userId) {
var Todo = this; var Todo = this;
if (category === '') { const query = getQueryTodo({}, userId);
const query = getQueryTodo({}, userId); return Todo.aggregate(query)
.then(ris => {
return Todo.aggregate(query) // console.log('ris TODO:', ris);
.then(ris => { //return tools.mapSort(ris)
// console.log('ris TODO:', ris); return ris
//return tools.mapSort(ris)
return ris
});
} else {
return Todo.find({
'userId': userId,
'category': category,
}); });
}
}; };
TodoSchema.statics.getArrIdParentInTable = function (userId) { TodoSchema.statics.getArrIdParentInTable = function (userId) {
@@ -216,7 +207,7 @@ TodoSchema.statics.getAllTodo = async function (userId) {
obj.arrcategories = await Todo.getArrIdParentInTable(userId); obj.arrcategories = await Todo.getArrIdParentInTable(userId);
console.log('obj.arrcategories', obj.arrcategories); // console.log('obj.arrcategories', obj.arrcategories);
let arrtodos = []; let arrtodos = [];
if (obj.arrcategories.length > 0) { if (obj.arrcategories.length > 0) {
@@ -226,7 +217,10 @@ TodoSchema.statics.getAllTodo = async function (userId) {
if (arrfiltrato.length > 0) { if (arrfiltrato.length > 0) {
const arrmap = tools.mapSort(arrfiltrato); const arrmap = tools.mapSort(arrfiltrato);
arrtodos.push(arrmap); 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; obj.arrtodos = arrtodos;
console.log('obj.arrtodos', obj.arrtodos); // console.log('obj.arrtodos:');
// logtodo(obj.arrtodos);
return obj; 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 { class CalcTodo {
constructor(phase) { constructor(phase) {

View File

@@ -134,6 +134,8 @@ router.get('/:userId', authenticate, (req, res) => {
if (!!objprojects.arrproj) if (!!objprojects.arrproj)
tools.mylog('projects', objprojects.arrproj.length); tools.mylog('projects', objprojects.arrproj.length);
// console.log(objprojects.arrproj);
return objprojects return objprojects
}).then((objprojects) => { }).then((objprojects) => {

View File

@@ -235,7 +235,7 @@ module.exports = {
if (linkedList.length > sortedList.length) { if (linkedList.length > sortedList.length) {
// If are not in the list, I'll put at the bottom of the list // 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) { for (const itemlinked of linkedList) {
const elemtrov = sortedList.find((item) => item._id === itemlinked._id); const elemtrov = sortedList.find((item) => item._id === itemlinked._id);
if (elemtrov === undefined) { if (elemtrov === undefined) {