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

@@ -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) {