From 3f8a2abd66ddefce4249fff7f562eee1562abc0f Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Sat, 11 Dec 2021 00:25:54 +0100 Subject: [PATCH] - Aggiunto Filtri - Finder --- src/server/classes/queryclass.js | 8 +++++++- src/server/models/myskill.js | 31 ++++++++++++++++++++++++++++++- src/server/router/index_router.js | 6 +++--- src/server/tools/general.js | 30 ++++++++++++++++++++---------- src/server/tools/shared_nodejs.js | 2 ++ 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/src/server/classes/queryclass.js b/src/server/classes/queryclass.js index 3eed427..ff320cc 100755 --- a/src/server/classes/queryclass.js +++ b/src/server/classes/queryclass.js @@ -1,18 +1,24 @@ class CParamsQuery { constructor(params) { + this.table = params.table; this.startRow = params.startRow; this.endRow = params.endRow; - // this.count = params.count; this.filter = params.filter; + this.filterand = params.filterand; + this.filtersearch = params.filtersearch; + this.filtercustom = params.filtercustom; this.sortBy = params.sortBy; this.descending = params.descending; + this.userId = params.userId; + this.codeId = params.codeId; 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; this.lk_proj = params.lk_proj; + this.lk_col2 = params.lk_col2; } } diff --git a/src/server/models/myskill.js b/src/server/models/myskill.js index 7a95879..91b3f29 100755 --- a/src/server/models/myskill.js +++ b/src/server/models/myskill.js @@ -99,11 +99,40 @@ MySkillSchema.statics.findAllIdApp = function(idapp) { }; MySkillSchema.statics.getFieldsForSearch = function() { - return [{field: 'idSkill', type: tools.FieldType.Number}]; + return [{field: 'idSkill', type: tools.FieldType.Number} + ,{field: 'note', type: tools.FieldType.String} + ,{field: 'subTitle', type: tools.FieldType.String} + ]; }; MySkillSchema.statics.executeQueryTable = function(idapp, params) { params.fieldsearch = this.getFieldsForSearch(); + + const otherparams = { + lk_tab: 'users', + lk_LF: 'userId', + lk_FF: '_id', + lk_as: 'user', + af_objId_tab: 'myId', + lk_proj: { + idSkill: 1, + idStatusSkill: 1, + idCity: 1, + numLevel: 1, + photos: 1, + note: 1, + subTitle: 1, + date_created: 1, + date_updated: 1, + userId: 1, + username: 1, + name: 1, + surname: 1, + }, + }; + + params = { ...params, ...otherparams }; + return tools.executeQueryTable(this, idapp, params); }; diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index ff934dc..8d196fe 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -319,9 +319,9 @@ router.post('/settable', authenticate, (req, res) => { mydata.idapp = req.user.idapp; if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) { - if (mydata['_id'] === undefined) { - mydata._id = 1; - } + //if (mydata['_id'] === undefined) { + // mydata._id = 1; + //} } else if (params.table === 'hours') { } else { diff --git a/src/server/tools/general.js b/src/server/tools/general.js index 4dd51a8..b42d80f 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -1106,9 +1106,7 @@ module.exports = { return (myapp) ? myapp.telegram_key : ''; }, - getQueryTable(idapp, params) { - // console.log('idapp', idapp); - // console.table(params); + getQueryTable: function(idapp, params) { if (typeof params.startRow !== 'number') { throw new Error('startRow must be number'); @@ -1257,6 +1255,14 @@ module.exports = { } + if (params.filtercustom) { + filtriadded.push(...params.filtercustom); + } + + if (params.filtersearch) { + filtriadded.push(...params.filtersearch); + } + if (filtriadded.length > 0) query.push({$match: {$and: filtriadded}}); @@ -1340,14 +1346,18 @@ module.exports = { async executeQueryTable(mythistable, idapp, params) { let query = this.getQueryTable(idapp, params); - const [ris] = await mythistable.aggregate(query); + try { + const [ris] = await mythistable.aggregate(query); - if (ris) { - // console.table(ris.rows); - // console.log('ROW ', ris.count); - return ({count: ris.count, rows: ris.rows}); - } else { - return ({count: 0, rows: []}); + if (ris) { + // console.table(ris.rows); + // console.log('ROW ', ris.count); + return ({count: ris.count, rows: ris.rows}); + } else { + return ({count: 0, rows: []}); + } + } catch (e) { + console.log('error', e); } }, diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js index a80953c..f862584 100755 --- a/src/server/tools/shared_nodejs.js +++ b/src/server/tools/shared_nodejs.js @@ -29,6 +29,8 @@ module.exports = { FILTER_TO_MAKE_MEMBERSHIP_CARD: 524288, FILTER_MEMBERSHIP_CARD_OK: 1048576, + FILTER_MYSKILL_SKILL: 1, + REPORT_FILT_RESP: 1, REPORT_FILT_ATTIVITA: 2,