diff --git a/src/server/classes/queryclass.js b/src/server/classes/queryclass.js index 827b8d8..3eed427 100755 --- a/src/server/classes/queryclass.js +++ b/src/server/classes/queryclass.js @@ -8,6 +8,7 @@ class CParamsQuery { this.sortBy = params.sortBy; this.descending = params.descending; this.lk_tab = params.lk_tab; + this.af_objId_tab = params.af_objId_tab; this.lk_LF = params.lk_LF; this.lk_FF = params.lk_FF; this.lk_as = params.lk_as; diff --git a/src/server/models/hours.js b/src/server/models/hours.js index 6d5dc8f..2f7ac80 100755 --- a/src/server/models/hours.js +++ b/src/server/models/hours.js @@ -126,6 +126,7 @@ module.exports.getTotalHoursByDate = async function (idapp, userId, date) { { $gte: new Date(tools.getstrDateYYYY_MM_DD(date)), $lte: new Date(tools.getstrDateYYYY_MM_DD(tools.AddDate(date, 1))) + // $lte: new Date('2023-01-01') } }, }, @@ -145,6 +146,8 @@ module.exports.getTotalHoursByDate = async function (idapp, userId, date) { ] ; + + try { const ris = await Hours.aggregate(myfind); if (ris.length > 0) { diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 93c535e..2f78477 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -281,6 +281,8 @@ router.post('/settable', authenticate, (req, res) => { if (mydata["_id"] === undefined) { mydata._id = 1; } + } else if (params.table === 'hours') { + } else { if (mydata["_id"] === undefined) { mydata._id = new ObjectID() @@ -302,7 +304,11 @@ router.post('/settable', authenticate, (req, res) => { if (e.code === 11000) { const id = mytablerec._id; delete mytablerec._doc['_id']; - return mytablestrutt.findByIdAndUpdate(id, { $set: mytablerec._doc }).then(async (rec) => { + const myfields = mytablerec._doc; + if (!myfields.userId) { + myfields.userId = req.user._id.toString(); + } + return mytablestrutt.findByIdAndUpdate(id, { $set: myfields }).then(async (rec) => { return res.send(rec); }).catch((err) => { tools.mylog('error: ', err.message); diff --git a/src/server/router/projects_router.js b/src/server/router/projects_router.js index dbccc8b..27e20d9 100755 --- a/src/server/router/projects_router.js +++ b/src/server/router/projects_router.js @@ -47,7 +47,7 @@ router.post('/', authenticate, (req, res) => { .then(record => { // tools.mylog('REC SAVED :', record.descr); - tools.sendNotificationToUser(todo.userId, titolo + ' ' + record.descr, record.descr, '/todo/' + todo.category, '', 'todo', []) + tools.sendNotificationToUser(record.userId, titolo + ' ' + record.descr, record.descr, '/todo/' + record._id, '', 'todo', []) res.send({ record: record._doc }); diff --git a/src/server/router/report_router.js b/src/server/router/report_router.js index c3d5cd8..241af69 100755 --- a/src/server/router/report_router.js +++ b/src/server/router/report_router.js @@ -61,7 +61,7 @@ router.post('/load', authenticate, async (req, res) => { //let myhours = await Hours.getHoursByIdCat(idapp, myuser._id, myproj._id, date_start, date_end); let mydate = new Date(mydatets); let rechours = await Hours.getHoursByDate(idapp, myuser._id, mydate); - let ressum = await Hours.getTotalHoursByDate(idapp, myuser._id, mydate); + let ressum = await Hours.getTotalHoursByDate(idapp, myuser.id, mydate); if (tools.isMonday(mydatets)) { totalacchours[myuser.username] = 0; @@ -98,7 +98,7 @@ router.post('/load', authenticate, async (req, res) => { colors.themebgcolor = mytodo.themebgcolor; colors.themecolor = mytodo.themecolor; myproj = await Project.findProjectByUserId('', mytodo.category); - if (!themebgcolor && myproj) { + if (!colors.themebgcolor && myproj) { colors.themebgcolor = myproj.themebgcolor; colors.themecolor = myproj.themecolor; } diff --git a/src/server/tools/general.js b/src/server/tools/general.js index 20ab416..af47700 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -1115,12 +1115,20 @@ module.exports = { if (numrowend < 0) numrowend = 1; + let mylkLF = params.lk_LF; + if (params.af_objId_tab) { + query.push( + { "$addFields": { "myId": { "$toObjectId": '$' + params.lk_LF } } } + ); + mylkLF = 'myId'; + } + if (params.lk_tab) { query.push( { $lookup: { from: params.lk_tab, - localField: params.lk_LF, // field in my collection + localField: mylkLF, // field in my collection foreignField: params.lk_FF, // field in the 'from' collection as: params.lk_as }