Updated Project calculation for hours and progress.
This commit is contained in:
1
server/calculations/todo.js
Normal file
1
server/calculations/todo.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -29,9 +29,11 @@ var ProjectSchema = new mongoose.Schema({
|
|||||||
},
|
},
|
||||||
hoursplanned: {
|
hoursplanned: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
default: 0
|
||||||
},
|
},
|
||||||
hoursworked: {
|
hoursworked: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
default: 0
|
||||||
},
|
},
|
||||||
id_parent: {
|
id_parent: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -64,6 +66,7 @@ var ProjectSchema = new mongoose.Schema({
|
|||||||
},
|
},
|
||||||
progressCalc: {
|
progressCalc: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
default: 0
|
||||||
},
|
},
|
||||||
modified: {
|
modified: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -93,15 +96,37 @@ ProjectSchema.methods.toJSON = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ProjectSchema.statics.findByUserIdAndCat = function (userId, category) {
|
ProjectSchema.statics.findByUserIdAndIdParent = function (userId, id_parent) {
|
||||||
var Project = this;
|
var Project = this;
|
||||||
|
|
||||||
|
if (userId === '') {
|
||||||
|
return Project.find({
|
||||||
|
'id_parent': id_parent,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
return Project.find({
|
return Project.find({
|
||||||
'userId': userId,
|
'userId': userId,
|
||||||
'category': category,
|
'id_parent': id_parent,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProjectSchema.statics.findProjectByUserId = function (userId, idproj) {
|
||||||
|
var Project = this;
|
||||||
|
|
||||||
|
if (userId === '') {
|
||||||
|
return Project.findOne({
|
||||||
|
'_id': idproj,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Project.findOne({
|
||||||
|
'userId': userId,
|
||||||
|
'_id': idproj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ProjectSchema.statics.findAllByUserId = function (userId) {
|
ProjectSchema.statics.findAllByUserId = function (userId) {
|
||||||
var Project = this;
|
var Project = this;
|
||||||
|
|
||||||
@@ -113,12 +138,27 @@ ProjectSchema.statics.findAllByUserId = function (userId) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ProjectSchema.statics.getArrCategoryInTable = function (userId) {
|
ProjectSchema.statics.getArrIdParentInTable = function (userId) {
|
||||||
var Project = this;
|
var Project = this;
|
||||||
|
|
||||||
return Project.find({ 'userId': userId }).distinct("category")
|
return Project.find({ 'userId': userId }).distinct("id_parent")
|
||||||
.then(arrcategory => {
|
|
||||||
return arrcategory
|
};
|
||||||
|
|
||||||
|
ProjectSchema.statics.getIdParentByIdProj = function (idProj) {
|
||||||
|
var Project = this;
|
||||||
|
|
||||||
|
console.log('INIT getIdParentByIdProj', idProj);
|
||||||
|
|
||||||
|
return Project.findOne({ '_id': idProj }).then(rec => {
|
||||||
|
if (!!rec) {
|
||||||
|
console.log('getIdParentByIdProj', rec.id_parent);
|
||||||
|
return rec.id_parent;
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
return '';
|
||||||
})
|
})
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -134,6 +174,40 @@ ProjectSchema.statics.getAllProjects = async function (userId) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProjectSchema.statics.updateCalc = async function (userId, idproj, objdatacalc, recIn) {
|
||||||
|
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!!recIn) {
|
||||||
|
return resolve(recIn);
|
||||||
|
} else {
|
||||||
|
return resolve(Project.findProjectByUserId(userId, idproj))
|
||||||
|
}
|
||||||
|
}).then((myproj) => {
|
||||||
|
if (!!myproj) {
|
||||||
|
// console.log('myproj', myproj);
|
||||||
|
|
||||||
|
objdatacalc.setValuesToRecord(myproj);
|
||||||
|
|
||||||
|
console.log('updateCalc', myproj._id, objdatacalc);
|
||||||
|
|
||||||
|
myproj.save()
|
||||||
|
.then(() => {
|
||||||
|
// console.log('salvato proj!');
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log("Error updateCalc", err.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).catch(e => {
|
||||||
|
console.log('Error: ', e);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ProjectSchema.pre('save', function (next) {
|
ProjectSchema.pre('save', function (next) {
|
||||||
// var Project = this;
|
// var Project = this;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
|
|
||||||
|
var { Project } = require('./project');
|
||||||
|
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.level = "F";
|
mongoose.level = "F";
|
||||||
|
|
||||||
@@ -40,6 +42,9 @@ var TodoSchema = new mongoose.Schema({
|
|||||||
modify_at: {
|
modify_at: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
|
start_date: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
completed_at: {
|
completed_at: {
|
||||||
type: Date
|
type: Date
|
||||||
},
|
},
|
||||||
@@ -56,6 +61,18 @@ var TodoSchema = new mongoose.Schema({
|
|||||||
progress: {
|
progress: {
|
||||||
type: Number,
|
type: Number,
|
||||||
},
|
},
|
||||||
|
phase: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
|
assigned_to_userId: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
hoursplanned: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
|
hoursworked: {
|
||||||
|
type: Number,
|
||||||
|
},
|
||||||
modified: {
|
modified: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
},
|
},
|
||||||
@@ -71,13 +88,19 @@ TodoSchema.methods.toJSON = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TodoSchema.statics.findByUserIdAndCat = function (userId, category) {
|
TodoSchema.statics.findByUserIdAndIdParent = function (userId, category) {
|
||||||
var Todo = this;
|
var Todo = this;
|
||||||
|
|
||||||
|
if (userId === '') {
|
||||||
|
return Todo.find({
|
||||||
|
'category': category,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
return Todo.find({
|
return Todo.find({
|
||||||
'userId': userId,
|
'userId': userId,
|
||||||
'category': category,
|
'category': category,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') {
|
TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') {
|
||||||
@@ -87,7 +110,8 @@ TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') {
|
|||||||
return Todo.find({
|
return Todo.find({
|
||||||
'userId': userId,
|
'userId': userId,
|
||||||
}).then(ris => {
|
}).then(ris => {
|
||||||
return tools.mapSort(ris)
|
//return tools.mapSort(ris)
|
||||||
|
return ris
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -98,7 +122,7 @@ TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TodoSchema.statics.getArrCategoryInTable = function (userId) {
|
TodoSchema.statics.getArrIdParentInTable = function (userId) {
|
||||||
var Todo = this;
|
var Todo = this;
|
||||||
|
|
||||||
return Todo.find({ 'userId': userId }).distinct("category")
|
return Todo.find({ 'userId': userId }).distinct("category")
|
||||||
@@ -112,16 +136,16 @@ TodoSchema.statics.getAllTodo = async function (userId) {
|
|||||||
var Todo = this;
|
var Todo = this;
|
||||||
|
|
||||||
const arralltodo = await Todo.findAllByUserIdAndCat(userId);
|
const arralltodo = await Todo.findAllByUserIdAndCat(userId);
|
||||||
// console.log('arralltodo', );
|
// console.log('arralltodo', arralltodo);
|
||||||
|
|
||||||
let obj = [];
|
let obj = [];
|
||||||
|
|
||||||
obj.arrcategories = await Todo.getArrCategoryInTable(userId);
|
obj.arrcategories = await Todo.getArrIdParentInTable(userId);
|
||||||
|
|
||||||
const arrtodos = [];
|
const arrtodos = [];
|
||||||
if (obj.arrcategories.length > 0) {
|
if (obj.arrcategories.length > 0) {
|
||||||
for (let mycat in obj.arrcategories) {
|
for (let mycat in obj.arrcategories) {
|
||||||
arrtodos.push(arralltodo.filter(item => item.category === obj.arrcategories[mycat]))
|
arrtodos.push(tools.mapSort(arralltodo.filter(item => item.category === obj.arrcategories[mycat])))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +157,144 @@ TodoSchema.statics.getAllTodo = async function (userId) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CalcTodo {
|
||||||
|
constructor() {
|
||||||
|
this.mydata = {
|
||||||
|
hoursworked: 0,
|
||||||
|
hoursplanned: 0,
|
||||||
|
progressCalc: 0,
|
||||||
|
numitem: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addData(datain) {
|
||||||
|
if (!!datain) {
|
||||||
|
this.mydata.hoursworked += datain.hoursworked;
|
||||||
|
this.mydata.hoursplanned += datain.hoursplanned;
|
||||||
|
if (!!datain.progressCalc)
|
||||||
|
this.mydata.progressCalc += datain.progressCalc;
|
||||||
|
else if (!!datain.progress)
|
||||||
|
this.mydata.progressCalc += datain.progress;
|
||||||
|
|
||||||
|
this.mydata.numitem++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endDataCalc() {
|
||||||
|
if (this.mydata.numitem > 0) {
|
||||||
|
this.mydata.progressCalc = Math.round(this.mydata.progressCalc / this.mydata.numitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setValuesToRecord(objout) {
|
||||||
|
objout.hoursworked = this.mydata.hoursworked;
|
||||||
|
objout.hoursplanned = this.mydata.hoursplanned;
|
||||||
|
objout.progressCalc = this.mydata.progressCalc;
|
||||||
|
}
|
||||||
|
|
||||||
|
getData() {
|
||||||
|
// return tools.jsonCopy(this.mydata);
|
||||||
|
return { ...this.mydata }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TodoSchema.statics.calculateTreeTodo = async function (userId, idproj, calcalsoUpper, masterproj, nocalcDown) {
|
||||||
|
console.log('calculateTreeTodo', idproj);
|
||||||
|
|
||||||
|
let objdata = new CalcTodo();
|
||||||
|
|
||||||
|
let promiseChain = Promise.resolve();
|
||||||
|
|
||||||
|
return await Project.findByUserIdAndIdParent(userId, idproj)
|
||||||
|
.then(arrsubproj => {
|
||||||
|
console.log('arrsubproj', 'userId', userId, 'idproj', idproj, arrsubproj.length);
|
||||||
|
|
||||||
|
if (!nocalcDown) {
|
||||||
|
// 1) Calculate the SubProjects of this project Main
|
||||||
|
for (const subproj of arrsubproj) {
|
||||||
|
if (!calcalsoUpper) { // not include the first Project because it was already calculated before
|
||||||
|
promiseChain = promiseChain.then(() => {
|
||||||
|
return Todo.calculateTreeTodo(userId, subproj._id, calcalsoUpper, masterproj, true)
|
||||||
|
.then((subobjdata) => {
|
||||||
|
objdata.addData(subobjdata);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promiseChain = promiseChain.then(() => {
|
||||||
|
objdata.addData(subproj);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return promiseChain;
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
console.log('objdata', objdata);
|
||||||
|
// 2) Calculate the Todos of this project
|
||||||
|
return Todo.calculateTodoHoursAndProgress(userId, idproj);
|
||||||
|
})
|
||||||
|
.then((objdatatodos) => {
|
||||||
|
objdata.addData(objdatatodos);
|
||||||
|
|
||||||
|
// End Calculate
|
||||||
|
objdata.endDataCalc();
|
||||||
|
|
||||||
|
// Update into the DB:
|
||||||
|
return Project.updateCalc(userId, idproj, objdata, null)
|
||||||
|
.then(() => {
|
||||||
|
return objdata.getData();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then((ris) => {
|
||||||
|
if (calcalsoUpper) {
|
||||||
|
return Project.getIdParentByIdProj(idproj)
|
||||||
|
.then(idparent => {
|
||||||
|
console.log('idparent', idparent);
|
||||||
|
if (!!idparent) {
|
||||||
|
// Calculate also the upper Projects !
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
Todo.calculateTreeTodo(userId, idparent, true, masterproj, true);
|
||||||
|
resolve(ris)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
resolve()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
resolve()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TodoSchema.statics.calculateTodoHoursAndProgress = async function (userId, idproj) {
|
||||||
|
var Todo = this;
|
||||||
|
|
||||||
|
let objdata = new CalcTodo();
|
||||||
|
|
||||||
|
return await Todo.findByUserIdAndIdParent(userId, idproj)
|
||||||
|
.then(arrtodo => {
|
||||||
|
for (let itemtodo of arrtodo) {
|
||||||
|
objdata.addData(itemtodo);
|
||||||
|
}
|
||||||
|
|
||||||
|
objdata.endDataCalc();
|
||||||
|
|
||||||
|
return objdata.getData();
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.log('Error: ', e);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
TodoSchema.pre('save', function (next) {
|
TodoSchema.pre('save', function (next) {
|
||||||
// var todo = this;
|
// var todo = this;
|
||||||
|
|
||||||
@@ -142,7 +304,6 @@ TodoSchema.pre('save', function (next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Todo = mongoose.model('Todos', TodoSchema);
|
var Todo = mongoose.model('Todos', TodoSchema);
|
||||||
|
|
||||||
module.exports = { Todo };
|
module.exports = { Todo };
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ var { authenticate } = require('../middleware/authenticate');
|
|||||||
// var mongoose = require('mongoose');
|
// var mongoose = require('mongoose');
|
||||||
|
|
||||||
var { Project } = require('../models/project');
|
var { Project } = require('../models/project');
|
||||||
|
const { Todo } = require('./../models/todo');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
@@ -65,7 +66,6 @@ router.post('/', authenticate, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router.patch('/:id', authenticate, (req, res) => {
|
router.patch('/:id', authenticate, (req, res) => {
|
||||||
var id = req.params.id;
|
var id = req.params.id;
|
||||||
var body = _.pick(req.body, tools.allfieldProject());
|
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
|
// Extract all the projects of the userId only
|
||||||
// Project.findAllByUserIdAndCat(userId, category).then((projects) => {
|
// Project.findAllByUserIdAndCat(userId, category).then((projects) => {
|
||||||
Project.getAllProjects(userId).then((objprojects) => {
|
return Project.getAllProjects(userId).then((objprojects) => {
|
||||||
tools.mylog('projects', objprojects.arrproj.length);
|
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);
|
// if (tools.EXECUTE_CALCPROJ) {
|
||||||
|
// return calcProjects('', objprojects).then(objout => {
|
||||||
// res.send({ projects: objprojects.arrproj, categories: objprojects.arrcategories });
|
// res.send({ projects: objprojects.arrproj });
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
res.send({ projects: objprojects.arrproj });
|
||||||
|
// }
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
res.status(400).send(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) {
|
if (myarr.length > 0) {
|
||||||
// Calculate the Progression of the Project
|
let promiseChain = Promise.resolve();
|
||||||
|
|
||||||
|
for (const rec of myarr) {
|
||||||
|
promiseChain = promiseChain.then(() => {
|
||||||
// Find the todos for this project
|
// Find the todos for this project
|
||||||
|
// Calculate the Progression of the Project // sum the progression
|
||||||
// sum the progression
|
return Todo.calculateTreeTodo(userId, rec._id, false, rec._id, false)
|
||||||
|
})
|
||||||
myarr[indrec].progressCalc = Math.round(Math.random() * 100);
|
}
|
||||||
|
return promiseChain
|
||||||
|
} else {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return myarr
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ const tools = require('../tools/general');
|
|||||||
|
|
||||||
var server_constants = require('../tools/server_constants');
|
var server_constants = require('../tools/server_constants');
|
||||||
|
|
||||||
|
var { Project } = require('../models/project');
|
||||||
|
|
||||||
var { authenticate } = require('../middleware/authenticate');
|
var { authenticate } = require('../middleware/authenticate');
|
||||||
|
|
||||||
var mongoose = require('mongoose');
|
var mongoose = require('mongoose');
|
||||||
@@ -66,12 +68,11 @@ router.post('/', authenticate, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router.patch('/:id', authenticate, (req, res) => {
|
router.patch('/:id', authenticate, (req, res) => {
|
||||||
var id = req.params.id;
|
var id = req.params.id;
|
||||||
var body = _.pick(req.body, tools.allfieldTodo());
|
var body = _.pick(req.body, tools.allfieldTodo());
|
||||||
|
|
||||||
tools.mylogshow('PATCH TODO: ', id)
|
tools.mylogshow('PATCH TODO: ', id);
|
||||||
|
|
||||||
if (!ObjectID.isValid(id)) {
|
if (!ObjectID.isValid(id)) {
|
||||||
tools.mylog('ERROR: id not VALID', id);
|
tools.mylog('ERROR: id not VALID', id);
|
||||||
@@ -79,13 +80,16 @@ router.patch('/:id', authenticate, (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Todo.findByIdAndUpdate(id, { $set: body }, { new: true })
|
||||||
Todo.findByIdAndUpdate(id, { $set: body }, { new: true }).then((todo) => {
|
.then((todo) => {
|
||||||
if (!todo) {
|
if (!todo) {
|
||||||
tools.mylogshow(' TODO NOT FOUND !: id:', id, 'body: ', body);
|
tools.mylogshow(' TODO NOT FOUND !: id:', id, 'body: ', body);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let level = 0;
|
||||||
|
return Todo.calculateTreeTodo(todo.userId, todo.category, true, todo.category, false)
|
||||||
|
.then(objdatacalc => {
|
||||||
tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
|
||||||
|
|
||||||
if (todo.userId !== String(req.user._id)) {
|
if (todo.userId !== String(req.user._id)) {
|
||||||
@@ -97,7 +101,9 @@ router.patch('/:id', authenticate, (req, res) => {
|
|||||||
|
|
||||||
tools.mylog('PATCH ', todo.descr, todo._id);
|
tools.mylog('PATCH ', todo.descr, todo._id);
|
||||||
|
|
||||||
res.send({ todo });
|
res.send({ todo, objdatacalc });
|
||||||
|
});
|
||||||
|
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
tools.mylogserr('Error patch TODO: ', e);
|
tools.mylogserr('Error patch TODO: ', e);
|
||||||
res.status(400).send();
|
res.status(400).send();
|
||||||
@@ -121,7 +127,6 @@ router.get('/:userId', authenticate, (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract all the todos of the userId only
|
// Extract all the todos of the userId only
|
||||||
// Todo.findAllByUserIdAndCat(userId, category).then((todos) => {
|
|
||||||
Todo.getAllTodo(userId).then((objtodos) => {
|
Todo.getAllTodo(userId).then((objtodos) => {
|
||||||
|
|
||||||
tools.mylog('todos', objtodos.arrtodos.length);
|
tools.mylog('todos', objtodos.arrtodos.length);
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ if (process.env.GCM_API_KEY !== "")
|
|||||||
webpush.setGCMAPIKey(process.env.GCM_API_KEY);
|
webpush.setGCMAPIKey(process.env.GCM_API_KEY);
|
||||||
|
|
||||||
webpush.setVapidDetails(subject, publicVapidKey, privateVapidKey);
|
webpush.setVapidDetails(subject, publicVapidKey, privateVapidKey);
|
||||||
console.log('setVapidDetails... config...');
|
// console.log('setVapidDetails... config...');
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
FIRST_PROJ: '__PROJECTS',
|
||||||
|
EXECUTE_CALCPROJ: true,
|
||||||
getHostname: function () {
|
getHostname: function () {
|
||||||
return os.hostname()
|
return os.hostname()
|
||||||
},
|
},
|
||||||
@@ -50,7 +52,7 @@ module.exports = {
|
|||||||
|
|
||||||
allfieldTodo: function () {
|
allfieldTodo: function () {
|
||||||
return ['userId', 'pos', 'category', 'descr', 'priority', 'status', 'created_at', 'modify_at',
|
return ['userId', 'pos', 'category', 'descr', 'priority', 'status', 'created_at', 'modify_at',
|
||||||
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'progress', 'modified']
|
'completed_at', 'expiring_at', 'enableExpiring', 'id_prev', 'progress', 'modified', 'phase', 'assigned_to_userId', 'hoursplanned', 'hoursworked', 'start_date']
|
||||||
},
|
},
|
||||||
|
|
||||||
allfieldTodoWithId: function () {
|
allfieldTodoWithId: function () {
|
||||||
@@ -146,16 +148,16 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
console.log('************ INVIO WEBPUSH.SENDNOTIFICATION N° ', conta, '/', trovati, 'A', subscription.browser);
|
console.log('************ INVIO WEBPUSH.SENDNOTIFICATION N° ', conta, '/', trovati, 'A', subscription.browser);
|
||||||
console.log('vapidDetails', pushOptions.vapidDetails);
|
// console.log('vapidDetails', pushOptions.vapidDetails);
|
||||||
|
|
||||||
payload.title = process.env.URLBASE_APP1 + ' Msg n° ' + conta + '/' + trovati;
|
payload.title = process.env.URLBASE_APP1 + ' Msg n° ' + conta + '/' + trovati;
|
||||||
// payload.message += subscription.browser ;
|
// payload.message += subscription.browser ;
|
||||||
|
|
||||||
const pushPayload = JSON.stringify(payload);
|
const pushPayload = JSON.stringify(payload);
|
||||||
|
|
||||||
console.log('A1) SUBS: pushSubscription', pushSubscription);
|
// console.log('A1) SUBS: pushSubscription', pushSubscription);
|
||||||
console.log('A2) OPZIONI: pushOptions', pushOptions);
|
// console.log('A2) OPZIONI: pushOptions', pushOptions);
|
||||||
console.log('A3) MSG_TO_SEND: pushPayload', pushPayload);
|
// console.log('A3) MSG_TO_SEND: pushPayload', pushPayload);
|
||||||
|
|
||||||
webpush.sendNotification(
|
webpush.sendNotification(
|
||||||
pushSubscription,
|
pushSubscription,
|
||||||
|
|||||||
Reference in New Issue
Block a user