From 9e2abc0c98d2a0fcf7798feda78bcc66cca756f5 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Sat, 3 Dec 2022 03:14:26 +0100 Subject: [PATCH] =?UTF-8?q?Attivare=20gli=20scambi=20RIS=20solo=20se=20si?= =?UTF-8?q?=20=C3=A8=20aggiunto=20almeno=201=20bene=20o=201=20servizio.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/models/user.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/server/models/user.js b/src/server/models/user.js index c5ff1f3..909770f 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -1492,6 +1492,7 @@ UserSchema.statics.getUserProfileByUsername = async function( 'profile.born_city_id': 1, 'profile.born_province': 1, 'profile.born_country': 1, + 'profile.calc': 1, email: 1, date_reg: 1, 'useraport.username': 1, @@ -1531,6 +1532,7 @@ UserSchema.statics.getUserProfileByUsername = async function( 'profile.born_city_id': 1, 'profile.born_province': 1, 'profile.born_country': 1, + 'profile.calc': 1, email: 1, date_reg: 1, 'useraport.username': 1, @@ -1571,6 +1573,7 @@ UserSchema.statics.getUserProfileByUsername = async function( 'profile.born_city_id': 1, 'profile.born_province': 1, 'profile.born_country': 1, + 'profile.calc': 1, 'mycities': 1, 'comune': 1, email: 1, @@ -1647,8 +1650,11 @@ UserSchema.statics.getUserProfileByUsername = async function( try { const ris = await User.aggregate(query); - if (ris && ris.length > 0) + if (ris && ris.length > 0) { + + ris[0].profile.calc = await User.calcOtherByUser(idapp, ris[0]._id); return ris[0]; + } } catch (e) { return null; } @@ -2448,6 +2454,7 @@ function getWhatToShow(idapp, username) { 'profile.born_city_id': 1, 'profile.born_province': 1, 'profile.born_country': 1, + 'profile.calc': 1, email: 1, date_reg: 1, }; @@ -2468,6 +2475,7 @@ function getWhatToShow_Unknown(idapp, username) { 'profile.sex': 1, 'profile.born_province': 1, 'profile.born_country': 1, + 'profile.calc': 1, date_reg: 1, }; @@ -2487,6 +2495,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function(idapp, username) { 'profile.sex': 1, 'profile.born_province': 1, 'profile.born_country': 1, + 'profile.calc': 1, reported: 1, date_report: 1, username_who_report: 1, @@ -3998,6 +4007,9 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) { recUser._doc.calcstat = await User.calculateStat(idapp, recUser.username); + recUser._doc.profile.calc = await User.calcOtherByUser(idapp, recUser._id); + + return recUser._doc; } catch (e) { @@ -4007,6 +4019,22 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) { return recUser; }; +UserSchema.statics.calcOtherByUser = async function(idapp, userId) { + + const {MySkill} = require('../models/myskill'); + const {MyGood} = require('../models/mygood'); + + let calc = {}; + + let numgoods = await MyGood.countDocuments({idapp, userId}); + let numskills = await MySkill.countDocuments({idapp, userId}); + + calc.numGoodsAndServices = numgoods + numskills; + + return calc; +}; + + UserSchema.statics.createNewSubRecord = async function(idapp, req) { const User = this;