diff --git a/src/server/models/extralist.js b/src/server/models/extralist.js index 715a61a..cb75fb2 100755 --- a/src/server/models/extralist.js +++ b/src/server/models/extralist.js @@ -164,6 +164,7 @@ ExtraListSchema.statics.getUsersList = function (idapp) { username: 1, name: 1, surname: 1, +lasttimeonline: 1, date_reg: 1, }) diff --git a/src/server/models/mybacheca.js b/src/server/models/mybacheca.js index 9210748..1a34d6c 100755 --- a/src/server/models/mybacheca.js +++ b/src/server/models/mybacheca.js @@ -6,7 +6,7 @@ mongoose.level = 'F'; const tools = require('../tools/general'); -const {ObjectID} = require('mongodb'); +const { ObjectID } = require('mongodb'); // Resolving error Unknown modifier: $pushAll mongoose.plugin(schema => { @@ -21,7 +21,7 @@ const MyBachecaSchema = new Schema({ type: String, required: true, }, - userId: {type: Schema.Types.ObjectId, ref: 'User'}, + userId: { type: Schema.Types.ObjectId, ref: 'User' }, idSector: { type: Number, }, @@ -86,9 +86,9 @@ const MyBachecaSchema = new Schema({ }, }); -MyBachecaSchema.pre('save', async function(next) { +MyBachecaSchema.pre('save', async function (next) { if (this.isNew) { - const myrec = await MyBacheca.findOne().limit(1).sort({_id: -1}); + const myrec = await MyBacheca.findOne().limit(1).sort({ _id: -1 }); if (!!myrec) { if (myrec._doc._id === 0) this._id = 1; @@ -105,12 +105,12 @@ MyBachecaSchema.pre('save', async function(next) { next(); }); -MyBachecaSchema.statics.findAllIdApp = async function(idapp) { +MyBachecaSchema.statics.findAllIdApp = async function (idapp) { const MyBacheca = this; const query = [ - {$match: {idapp}}, - {$sort: {descr: 1}}, + { $match: { idapp } }, + { $sort: { descr: 1 } }, ]; return await MyBacheca.aggregate(query).then((arrrec) => { @@ -119,21 +119,21 @@ MyBachecaSchema.statics.findAllIdApp = async function(idapp) { }; -MyBachecaSchema.statics.getFieldsForSearch = function() { +MyBachecaSchema.statics.getFieldsForSearch = function () { return []; }; -MyBachecaSchema.statics.getFieldsLastForSearch = function() { +MyBachecaSchema.statics.getFieldsLastForSearch = function () { return [ - {field: 'note', type: tools.FieldType.string}, - {field: 'descr', type: tools.FieldType.string}, - {field: 'recSkill.descr', type: tools.FieldType.string}, - {field: 'MyBacheca.descr', type: tools.FieldType.string}, + { field: 'note', type: tools.FieldType.string }, + { field: 'descr', type: tools.FieldType.string }, + { field: 'recSkill.descr', type: tools.FieldType.string }, + { field: 'MyBacheca.descr', type: tools.FieldType.string }, ]; }; -MyBachecaSchema.statics.executeQueryTable = function(idapp, params, user) { +MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) { params.fieldsearch = this.getFieldsForSearch(); params.fieldsearch_last = this.getFieldsLastForSearch(); @@ -167,6 +167,7 @@ MyBachecaSchema.statics.executeQueryTable = function(idapp, params, user) { username: 1, name: 1, surname: 1, + lasttimeonline: 1, 'profile.img': 1, "profile.mygroups": 1, 'profile.qualifica': 1, @@ -177,12 +178,12 @@ MyBachecaSchema.statics.executeQueryTable = function(idapp, params, user) { }, }; - params = {...params, ...otherparams}; + params = { ...params, ...otherparams }; return tools.executeQueryTable(this, idapp, params, user); }; -MyBachecaSchema.statics.getMyRecById = function(idapp, id) { +MyBachecaSchema.statics.getMyRecById = function (idapp, id) { const MyBacheca = this; const query = [ @@ -509,7 +510,7 @@ MyBachecaSchema.statics.getMyRecById = function(idapp, id) { }); }; -MyBachecaSchema.statics.getCompleteRecord = function(idapp, id) { +MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) { const MyBacheca = this; return MyBacheca.getMyRecById(idapp, id); @@ -519,4 +520,4 @@ MyBachecaSchema.statics.getCompleteRecord = function(idapp, id) { const MyBacheca = mongoose.model('MyBacheca', MyBachecaSchema); -module.exports = {MyBacheca}; +module.exports = { MyBacheca }; diff --git a/src/server/models/mygood.js b/src/server/models/mygood.js index 7bbd379..e4510d9 100755 --- a/src/server/models/mygood.js +++ b/src/server/models/mygood.js @@ -167,6 +167,7 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) { username: 1, name: 1, surname: 1, + lasttimeonline: 1, 'profile.img': 1, "profile.mygroups": 1, "profile.mycircuits": 1, diff --git a/src/server/models/myhosp.js b/src/server/models/myhosp.js index dba499a..2d59441 100755 --- a/src/server/models/myhosp.js +++ b/src/server/models/myhosp.js @@ -167,6 +167,7 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) { username: 1, name: 1, surname: 1, + lasttimeonline: 1, 'profile.img': 1, "profile.mygroups": 1, "profile.mycircuits": 1, diff --git a/src/server/models/myskill.js b/src/server/models/myskill.js index 6f208b7..3be9365 100755 --- a/src/server/models/myskill.js +++ b/src/server/models/myskill.js @@ -168,6 +168,7 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) { username: 1, name: 1, surname: 1, + lasttimeonline: 1, 'profile.img': 1, "profile.mygroups": 1, "profile.mycircuits": 1, diff --git a/src/server/models/sendnotif.js b/src/server/models/sendnotif.js index a3b8621..869e575 100755 --- a/src/server/models/sendnotif.js +++ b/src/server/models/sendnotif.js @@ -731,6 +731,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function(myrecnotifpass, r }, { name: 1, surname: 1, + lasttimeonline: 1, lang: 1, username: 1, 'profile.notifs': 1, diff --git a/src/server/models/user.js b/src/server/models/user.js index b35f860..b50b5ca 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -6,20 +6,20 @@ const _ = require('lodash'); const tools = require('../tools/general'); -const {Settings} = require('../models/settings'); +const { Settings } = require('../models/settings'); // const {ListaIngresso} = require('../models/listaingresso'); -const {Graduatoria} = require('../models/graduatoria'); +const { Graduatoria } = require('../models/graduatoria'); // const {Nave} = require('../models/nave'); // const {NavePersistente} = require('../models/navepersistente'); // const { ExtraList } = require('../models/extralist'); -const {MyGroup} = require('../models/mygroup'); -const {Circuit} = require('../models/circuit'); +const { MyGroup } = require('../models/mygroup'); +const { Circuit } = require('../models/circuit'); -const {Account} = require('../models/account'); -const {Movement} = require('../models/movement'); +const { Account } = require('../models/account'); +const { Movement } = require('../models/movement'); -const {ObjectID} = require('mongodb'); +const { ObjectID } = require('mongodb'); const i18n = require('i18n'); @@ -36,395 +36,395 @@ mongoose.plugin(schema => { mongoose.set('debug', false); const UserSchema = new mongoose.Schema({ - userId: { - type: String, - }, - email: { - type: String, - required: true, - trim: true, - minlength: 1, - unique: false, - /*validate: { - validator: validator.isEmail, - message: '{VALUE} is not a valid email' - }*/ - }, - idapp: { + userId: { + type: String, + }, + email: { + type: String, + required: true, + trim: true, + minlength: 1, + unique: false, + /*validate: { + validator: validator.isEmail, + message: '{VALUE} is not a valid email' + }*/ + }, + idapp: { + type: String, + required: true, + }, + group: { + type: Number, + }, + index: { + type: Number, + }, + ind_order: { + type: Number, + }, + old_order: { + type: Number, + }, + username: { + type: String, + required: true, + trim: true, + minlength: 6, + unique: false, + }, + name: { + type: String, + trim: true, + }, + surname: { + type: String, + trim: true, + }, + password: { + type: String, + require: true, + minlength: 6, + }, + lang: { + type: String, + require: true, + }, + linkreg: { + type: String, + required: false, + }, + verified_email: { + type: Boolean, + }, + made_gift: { + type: Boolean, + }, + tokens: [ + { + access: { type: String, required: true, }, - group: { - type: Number, - }, - index: { - type: Number, - }, - ind_order: { - type: Number, - }, - old_order: { - type: Number, - }, - username: { + browser: { type: String, required: true, - trim: true, - minlength: 6, - unique: false, }, - name: { + token: { type: String, - trim: true, + required: true, }, - surname: { - type: String, - trim: true, + date_login: { + type: Date, }, - password: { - type: String, - require: true, - minlength: 6, + }], + perm: { + type: Number, + }, + ipaddr: { + type: String, + }, + date_reg: { + type: Date, + }, + date_deleted: { + type: Date, + }, + date_tokenforgot: { + type: Date, + }, + tokenforgot: { + type: String, + }, + date_tokenreg: { + type: Date, + }, + tokenreg: { + type: String, + }, + lasttimeonline: { + type: Date, + }, + useragent: { + type: String, + }, + news_on: { + type: Boolean, + }, + aportador_solidario: { // da cancellare + type: String, + }, + verified_by_aportador: { + type: Boolean, + }, + notask_verif: { + type: Boolean, + }, + trust_modified: { + type: Date, + }, + aportador_iniziale: { + type: String, + }, + aportador_solidario_nome_completo: { + type: String, + }, + aportador_solidario_ind_order: { + type: Number, + }, + note: { + type: String, + }, + deleted: { + type: Boolean, + default: false, + }, + sospeso: { + type: Boolean, + }, + blocked: { + type: Boolean, + }, + username_who_block: { + type: String, + }, + date_blocked: { + type: Date, + }, + reported: { + type: Boolean, + }, + username_who_report: { + type: String, + }, + date_report: { + type: Date, + }, + non_voglio_imbarcarmi: { + type: Boolean, + }, + navinonpresenti: { + type: Boolean, + }, + subaccount: { + type: Boolean, + }, + cart: { + type: Object, + }, + profile: { + img: { + type: String, + }, + nationality: { + type: String, + }, + intcode_cell: { + type: String, + }, + iso2_cell: { + type: String, + }, + cell: { + type: String, + }, + country_pay: { + type: String, + }, + email_paypal: { + type: String, + }, + payeer_id: { + type: String, + }, + advcash_id: { + type: String, + }, + revolut: { + type: String, + }, + link_payment: { + type: String, + }, + note_payment: { + type: String, + }, + paymenttypes: [], + username_telegram: { + type: String, + }, + firstname_telegram: { + type: String, + }, + lastname_telegram: { + type: String, + }, + website: { + type: String, + }, + teleg_id: { + type: Number, + }, + teleg_id_old: { + type: Number, + }, + teleg_checkcode: { + type: Number, + }, + manage_telegram: { + type: Boolean, + }, + resplist: { + type: Boolean, + }, + workerslist: { + type: Boolean, + }, + dateofbirth: { + type: Date, + }, + born_city: { + type: String, + trim: true, + }, + born_city_id: { + type: Number, + }, + born_province: { + type: String, + trim: true, + }, + born_country: { + type: String, + trim: true, + }, + my_dream: { + type: String, + }, + saw_and_accepted: { + type: Number, + }, + saw_zoom_presentation: { + type: Boolean, + }, + ask_zoom_partecipato: { + type: Boolean, + }, + qualified: { + type: Boolean, + }, + qualified_2invitati: { + type: Boolean, + }, + special_req: { + type: Boolean, + }, + sex: { + type: Number, + }, + biografia: { + type: String, + }, + qualifica: { + type: String, + }, + motivazioni: { + type: String, + }, + competenze_professionalita: { + type: String, + }, + cosa_offrire: { + type: String, + }, + cosa_ricevere: { + type: String, + }, + altre_comunicazioni: { + type: Boolean, + }, + come_ci_hai_conosciuto: { + type: Boolean, + }, + socio: { + type: Boolean, + }, + socioresidente: { + type: Boolean, + }, + consiglio: { + type: Boolean, + }, + myshares: [ + { + description: { type: String }, + rating: { type: Number }, + }], + friends: [ + { + _id: false, + username: { type: String }, + date: { type: Date }, + }], // username + req_friends: [ + { + _id: false, + username: { type: String }, + date: { type: Date }, + }], // username + mygroups: [ + { + _id: false, + groupname: { type: String }, + date: { type: Date }, + }], // username + + mycircuits: [ + { + _id: false, + circuitname: { type: String }, + date: { type: Date }, + }], // username + + notifs: [ + { + _id: false, + dir: { type: Number }, + value: { type: Number }, }, - lang: { - type: String, - require: true, - }, - linkreg: { - type: String, - required: false, - }, - verified_email: { - type: Boolean, - }, - made_gift: { - type: Boolean, - }, - tokens: [ - { - access: { - type: String, - required: true, - }, - browser: { - type: String, - required: true, - }, - token: { - type: String, - required: true, - }, - date_login: { - type: Date, - }, - }], - perm: { + ], + notif_idCities: [ + { type: Number, - }, - ipaddr: { + }], + notif_provinces: [ + { type: String, - }, - date_reg: { - type: Date, - }, - date_deleted: { - type: Date, - }, - date_tokenforgot: { - type: Date, - }, - tokenforgot: { + }], + notif_regions: [ + { type: String, - }, - date_tokenreg: { - type: Date, - }, - tokenreg: { - type: String, - }, - lasttimeonline: { - type: Date, - }, - useragent: { - type: String, - }, - news_on: { - type: Boolean, - }, - aportador_solidario: { // da cancellare - type: String, - }, - verified_by_aportador: { - type: Boolean, - }, - notask_verif: { - type: Boolean, - }, - trust_modified: { - type: Date, - }, - aportador_iniziale: { - type: String, - }, - aportador_solidario_nome_completo: { - type: String, - }, - aportador_solidario_ind_order: { + }], + notif_sectors: [ + { type: Number, - }, - note: { - type: String, - }, - deleted: { - type: Boolean, - default: false, - }, - sospeso: { - type: Boolean, - }, - blocked: { - type: Boolean, - }, - username_who_block: { - type: String, - }, - date_blocked: { - type: Date, - }, - reported: { - type: Boolean, - }, - username_who_report: { - type: String, - }, - date_report: { - type: Date, - }, - non_voglio_imbarcarmi: { - type: Boolean, - }, - navinonpresenti: { - type: Boolean, - }, - subaccount: { - type: Boolean, - }, - cart: { - type: Object, - }, - profile: { - img: { - type: String, - }, - nationality: { - type: String, - }, - intcode_cell: { - type: String, - }, - iso2_cell: { - type: String, - }, - cell: { - type: String, - }, - country_pay: { - type: String, - }, - email_paypal: { - type: String, - }, - payeer_id: { - type: String, - }, - advcash_id: { - type: String, - }, - revolut: { - type: String, - }, - link_payment: { - type: String, - }, - note_payment: { - type: String, - }, - paymenttypes: [], - username_telegram: { - type: String, - }, - firstname_telegram: { - type: String, - }, - lastname_telegram: { - type: String, - }, - website: { - type: String, - }, - teleg_id: { - type: Number, - }, - teleg_id_old: { - type: Number, - }, - teleg_checkcode: { - type: Number, - }, - manage_telegram: { - type: Boolean, - }, - resplist: { - type: Boolean, - }, - workerslist: { - type: Boolean, - }, - dateofbirth: { - type: Date, - }, - born_city: { - type: String, - trim: true, - }, - born_city_id: { - type: Number, - }, - born_province: { - type: String, - trim: true, - }, - born_country: { - type: String, - trim: true, - }, - my_dream: { - type: String, - }, - saw_and_accepted: { - type: Number, - }, - saw_zoom_presentation: { - type: Boolean, - }, - ask_zoom_partecipato: { - type: Boolean, - }, - qualified: { - type: Boolean, - }, - qualified_2invitati: { - type: Boolean, - }, - special_req: { - type: Boolean, - }, - sex: { - type: Number, - }, - biografia: { - type: String, - }, - qualifica: { - type: String, - }, - motivazioni: { - type: String, - }, - competenze_professionalita: { - type: String, - }, - cosa_offrire: { - type: String, - }, - cosa_ricevere: { - type: String, - }, - altre_comunicazioni: { - type: Boolean, - }, - come_ci_hai_conosciuto: { - type: Boolean, - }, - socio: { - type: Boolean, - }, - socioresidente: { - type: Boolean, - }, - consiglio: { - type: Boolean, - }, - myshares: [ - { - description: {type: String}, - rating: {type: Number}, - }], - friends: [ - { - _id: false, - username: {type: String}, - date: {type: Date}, - }], // username - req_friends: [ - { - _id: false, - username: {type: String}, - date: {type: Date}, - }], // username - mygroups: [ - { - _id: false, - groupname: {type: String}, - date: {type: Date}, - }], // username + }], + notif_sector_goods: [ + { + type: Number, + }], + }, +}) + ; - mycircuits: [ - { - _id: false, - circuitname: {type: String}, - date: {type: Date}, - }], // username - - notifs: [ - { - _id: false, - dir: {type: Number}, - value: {type: Number}, - }, - ], - notif_idCities: [ - { - type: Number, - }], - notif_provinces: [ - { - type: String, - }], - notif_regions: [ - { - type: String, - }], - notif_sectors: [ - { - type: Number, - }], - notif_sector_goods: [ - { - type: Number, - }], - }, - }) -; - -UserSchema.methods.toJSON = function() { +UserSchema.methods.toJSON = function () { const user = this; const userObject = user.toObject(); return _.pick(userObject, ['_id', ...shared_consts.fieldsUserToChange()]); }; -UserSchema.methods.generateAuthToken = function(req) { +UserSchema.methods.generateAuthToken = function (req) { // console.log("GENERA TOKEN : "); const user = this; @@ -433,16 +433,16 @@ UserSchema.methods.generateAuthToken = function(req) { const access = 'auth'; const browser = useragent; - const token = jwt.sign({_id: user._id.toHexString(), access}, - process.env.SIGNCODE).toString(); + const token = jwt.sign({ _id: user._id.toHexString(), access }, + process.env.SIGNCODE).toString(); const date_login = new Date(); // CANCELLA IL PRECEDENTE ! - user.tokens = user.tokens.filter(function(tok) { + user.tokens = user.tokens.filter(function (tok) { return (tok.access !== access) || - ((tok.access === access) && (tok.browser !== browser)); + ((tok.access === access) && (tok.browser !== browser)); }); - user.tokens.push({access, browser, token, date_login}); + user.tokens.push({ access, browser, token, date_login }); user.lasttimeonline = new Date(); @@ -454,19 +454,19 @@ UserSchema.methods.generateAuthToken = function(req) { }); }; -UserSchema.statics.setPermissionsById = function(id, perm) { +UserSchema.statics.setPermissionsById = function (id, perm) { const user = this; - return user.findByIdAndUpdate(id, {$set: {perm}}).then((user) => { + return user.findByIdAndUpdate(id, { $set: { perm } }).then((user) => { if (user) - return res.send({code: server_constants.RIS_CODE_OK, msg: ''}); + return res.send({ code: server_constants.RIS_CODE_OK, msg: '' }); else - return res.send({code: server_constants.RIS_CODE_ERR, msg: ''}); + return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' }); }); }; -UserSchema.statics.setZoomPresenza = async function(idapp, id, presenza) { +UserSchema.statics.setZoomPresenza = async function (idapp, id, presenza) { const User = this; const telegrambot = require('../telegram/telegrambot'); @@ -475,36 +475,36 @@ UserSchema.statics.setZoomPresenza = async function(idapp, id, presenza) { allData.myuser = await User.getUserById(idapp, id); if (!!allData.myuser) allData.precDataUser = await User.getInfoUser(idapp, - allData.myuser.username); + allData.myuser.username); return await User.findByIdAndUpdate(id, - {$set: {'profile.saw_zoom_presentation': presenza}}).then((rec) => { - if (presenza) { - const messaggio = tools.get__('ZOOM_CONFERMATO'); - telegrambot.sendMsgTelegram(rec.idapp, rec.username, messaggio); - telegrambot.sendMsgTelegramToTheManagersAndZoomeri(idapp, + { $set: { 'profile.saw_zoom_presentation': presenza } }).then((rec) => { + if (presenza) { + const messaggio = tools.get__('ZOOM_CONFERMATO'); + telegrambot.sendMsgTelegram(rec.idapp, rec.username, messaggio); + telegrambot.sendMsgTelegramToTheManagersAndZoomeri(idapp, `L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato confermato per aver visto lo Zoom di Benvenuto`); - } else { - telegrambot.sendMsgTelegramToTheManagersAndZoomeri(idapp, + } else { + telegrambot.sendMsgTelegramToTheManagersAndZoomeri(idapp, `L\'utente ${rec.name} ${rec.surname} (${rec.username}) è stato annullata la sua richiesta per aver visto lo Zoom di Benvenuto! (Non ci risulta)`); - } + } - return User.findByIdAndUpdate(id, - {$set: {'profile.ask_zoom_partecipato': false}}).then((user) => { + return User.findByIdAndUpdate(id, + { $set: { 'profile.ask_zoom_partecipato': false } }).then((user) => { - User.checkIfSbloccatiRequisiti(idapp, allData, id); + User.checkIfSbloccatiRequisiti(idapp, allData, id); + }); }); - }); }; -UserSchema.statics.canHavePower = function(perm) { +UserSchema.statics.canHavePower = function (perm) { const User = this; try { let consentito = false; if (User.isAdmin(perm) || User.isManager(perm) || - User.isEditor(perm) || User.isFacilitatore(perm)) { + User.isEditor(perm) || User.isFacilitatore(perm)) { consentito = true; } @@ -514,61 +514,61 @@ UserSchema.statics.canHavePower = function(perm) { } }; -UserSchema.statics.isAdmin = function(perm) { +UserSchema.statics.isAdmin = function (perm) { try { return ((perm & shared_consts.Permissions.Admin) === - shared_consts.Permissions.Admin); + shared_consts.Permissions.Admin); } catch (e) { return false; } }; -UserSchema.statics.isManager = function(perm) { +UserSchema.statics.isManager = function (perm) { try { return ((perm & shared_consts.Permissions.Manager) === - shared_consts.Permissions.Manager); + shared_consts.Permissions.Manager); } catch (e) { return false; } }; -UserSchema.statics.isEditor = function(perm) { +UserSchema.statics.isEditor = function (perm) { try { return ((perm & shared_consts.Permissions.Editor) === - shared_consts.Permissions.Editor); + shared_consts.Permissions.Editor); } catch (e) { return false; } }; -UserSchema.statics.isZoomeri = function(perm) { +UserSchema.statics.isZoomeri = function (perm) { try { return ((perm & shared_consts.Permissions.Zoomeri) === - shared_consts.Permissions.Zoomeri); + shared_consts.Permissions.Zoomeri); } catch (e) { return false; } }; -UserSchema.statics.isDepartment = function(perm) { +UserSchema.statics.isDepartment = function (perm) { try { return ((perm & shared_consts.Permissions.Zoomeri) === - shared_consts.Permissions.Department); + shared_consts.Permissions.Department); } catch (e) { return false; } }; -UserSchema.statics.isFacilitatore = function(perm) { +UserSchema.statics.isFacilitatore = function (perm) { try { return ((perm & shared_consts.Permissions.Facilitatore) === - shared_consts.Permissions.Facilitatore); + shared_consts.Permissions.Facilitatore); } catch (e) { return false; } }; -UserSchema.statics.findByToken = function(token, typeaccess) { +UserSchema.statics.findByToken = function (token, typeaccess) { const User = this; let decoded; @@ -585,7 +585,7 @@ UserSchema.statics.findByToken = function(token, typeaccess) { }); }; -UserSchema.statics.findByTokenAnyAccess = function(token) { +UserSchema.statics.findByTokenAnyAccess = function (token) { const User = this; let decoded; @@ -601,7 +601,7 @@ UserSchema.statics.findByTokenAnyAccess = function(token) { }); }; -UserSchema.statics.findByCredentials = function(idapp, username, password, pwdcrypted) { +UserSchema.statics.findByCredentials = function (idapp, username, password, pwdcrypted) { const User = this; let pwd = ''; @@ -609,14 +609,14 @@ UserSchema.statics.findByCredentials = function(idapp, username, password, pwdcr return User.findOne({ idapp, - username: {$regex: regexp}, + username: { $regex: regexp }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}, + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }, { $and: [ - {deleted: {$exists: true, $eq: true}}, - {subaccount: {$exists: true, $eq: true}}, + { deleted: { $exists: true, $eq: true } }, + { subaccount: { $exists: true, $eq: true } }, ], }, ], @@ -627,8 +627,8 @@ UserSchema.statics.findByCredentials = function(idapp, username, password, pwdcr return User.findOne({ idapp, email: username.toLowerCase(), $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }); } else { return !user.deleted || (user.deleted && user.subaccount) ? user : null; @@ -662,7 +662,7 @@ UserSchema.statics.findByCredentials = function(idapp, username, password, pwdcr }); }; -UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, onlyifVerifiedByAportador) { +UserSchema.statics.findByUsername = async function (idapp, username, alsoemail, onlyifVerifiedByAportador) { const User = this; const myreg = ['^', username, '$'].join(''); @@ -672,18 +672,18 @@ UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, o return await User.findOne({ idapp: idapp, - username: {$regex: regexusername}, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + username: { $regex: regexusername }, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }).then(async (ris) => { if ((!ris) && (alsoemail)) { regexemail = new RegExp(['^', username.toLowerCase(), '$'].join(''), 'i'); return await User.findOne({ 'idapp': idapp, - 'email': {$regex: regexemail}, + 'email': { $regex: regexemail }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }); } return ris; @@ -700,7 +700,7 @@ UserSchema.statics.findByUsername = async function(idapp, username, alsoemail, o }); }; -UserSchema.statics.getProjectUser = function() { +UserSchema.statics.getProjectUser = function () { return { idapp: 1, lang: 1, @@ -710,6 +710,7 @@ UserSchema.statics.getProjectUser = function() { aportador_solidario: 1, name: 1, surname: 1, + lasttimeonline: 1, deleted: 1, reported: 1, date_report: 1, @@ -745,17 +746,17 @@ UserSchema.statics.getProjectUser = function() { }; -UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) { +UserSchema.statics.getUserShortDataByUsername = async function (idapp, username) { const User = this; let regexp = new RegExp(`^${username}$`, 'i'); const myrec = await User.findOne({ - 'idapp': idapp, - username: {$regex: regexp}, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, - this.getProjectUser(), + 'idapp': idapp, + username: { $regex: regexp }, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, + this.getProjectUser(), ).lean(); if (myrec) { @@ -768,17 +769,17 @@ UserSchema.statics.getUserShortDataByUsername = async function(idapp, username) return myrec; }; -UserSchema.statics.getUserShortDataByUsernameTelegram = async function(idapp, username_telegram) { +UserSchema.statics.getUserShortDataByUsernameTelegram = async function (idapp, username_telegram) { const User = this; let regexp = new RegExp(`^${username_telegram}$`, 'i'); const myrec = await User.findOne({ - 'idapp': idapp, - 'profile.username_telegram': {$regex: regexp}, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, - this.getProjectUser(), + 'idapp': idapp, + 'profile.username_telegram': { $regex: regexp }, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, + this.getProjectUser(), ).lean(); if (myrec) { @@ -791,8 +792,8 @@ UserSchema.statics.getUserShortDataByUsernameTelegram = async function(idapp, us return myrec; }; -UserSchema.statics.getDownlineByUsername = async function( - idapp, username, includemyself, onlynumber) { +UserSchema.statics.getDownlineByUsername = async function ( + idapp, username, includemyself, onlynumber) { if (username === undefined) return null; @@ -802,23 +803,23 @@ UserSchema.statics.getDownlineByUsername = async function( let myq = { idapp, aportador_solidario: username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }; if (!includemyself) { - myq = {...myq, username: {$ne: username}}; + myq = { ...myq, username: { $ne: username } }; } return arrrec; }; -UserSchema.statics.getQueryQualified = function() { +UserSchema.statics.getQueryQualified = function () { return [ { $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, { $or: [ @@ -827,15 +828,15 @@ UserSchema.statics.getQueryQualified = function() { }, { verified_email: true, - 'profile.teleg_id': {$gt: 1}, + 'profile.teleg_id': { $gt: 1 }, 'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED, // 'profile.saw_zoom_presentation': true, $or: [ - {'profile.link_payment': {$exists: true}}, - {'profile.email_paypal': {$exists: true}}, - {'profile.payeer_id': {$exists: true}}, - {'profile.advcash_id': {$exists: true}}, - {'profile.revolut': {$exists: true}}, + { 'profile.link_payment': { $exists: true } }, + { 'profile.email_paypal': { $exists: true } }, + { 'profile.payeer_id': { $exists: true } }, + { 'profile.advcash_id': { $exists: true } }, + { 'profile.revolut': { $exists: true } }, ], // 'profile.paymenttypes': { "$in": ['paypal'] }, // $where: "this.profile.paymenttypes.length >= 1", @@ -844,7 +845,7 @@ UserSchema.statics.getQueryQualified = function() { ]; }; -UserSchema.statics.isUserQualified7 = async function(idapp, username) { +UserSchema.statics.isUserQualified7 = async function (idapp, username) { const User = this; if (username === undefined) @@ -861,7 +862,7 @@ UserSchema.statics.isUserQualified7 = async function(idapp, username) { return !!myrec; }; -UserSchema.statics.isUserResidente = async function(idapp, username) { +UserSchema.statics.isUserResidente = async function (idapp, username) { const User = this; if (username === undefined) @@ -881,7 +882,7 @@ UserSchema.statics.isUserResidente = async function(idapp, username) { }; -UserSchema.statics.isUserConsiglio = async function(idapp, username) { +UserSchema.statics.isUserConsiglio = async function (idapp, username) { const User = this; if (username === undefined) @@ -901,7 +902,7 @@ UserSchema.statics.isUserConsiglio = async function(idapp, username) { }; -UserSchema.statics.isUserVisuProjects = async function(idapp, username) { +UserSchema.statics.isUserVisuProjects = async function (idapp, username) { const User = this; if (username === undefined) @@ -921,7 +922,7 @@ UserSchema.statics.isUserVisuProjects = async function(idapp, username) { }; -UserSchema.statics.isUserAlreadyQualified = async function(idapp, username) { +UserSchema.statics.isUserAlreadyQualified = async function (idapp, username) { const User = this; if (username === undefined) @@ -930,7 +931,7 @@ UserSchema.statics.isUserAlreadyQualified = async function(idapp, username) { const myquery = { 'idapp': idapp, 'username': username, - 'profile.qualified': {$exists: true, $eq: true}, + 'profile.qualified': { $exists: true, $eq: true }, }; const myrec = await User.findOne(myquery); @@ -938,8 +939,8 @@ UserSchema.statics.isUserAlreadyQualified = async function(idapp, username) { return !!myrec; }; -UserSchema.statics.isUserAlreadyQualified_2Invitati = async function( - idapp, username) { +UserSchema.statics.isUserAlreadyQualified_2Invitati = async function ( + idapp, username) { const User = this; if (username === undefined) @@ -948,7 +949,7 @@ UserSchema.statics.isUserAlreadyQualified_2Invitati = async function( const myquery = { 'idapp': idapp, 'username': username, - 'profile.qualified_2invitati': {$exists: true, $eq: true}, + 'profile.qualified_2invitati': { $exists: true, $eq: true }, }; const myrec = await User.findOne(myquery); @@ -956,7 +957,7 @@ UserSchema.statics.isUserAlreadyQualified_2Invitati = async function( return !!myrec; }; -UserSchema.statics.setUserQualified = async function(idapp, username) { +UserSchema.statics.setUserQualified = async function (idapp, username) { const User = this; if (username === undefined) @@ -968,13 +969,13 @@ UserSchema.statics.setUserQualified = async function(idapp, username) { }; const myrec = await User.findOneAndUpdate(myquery, - {$set: {'profile.qualified': true}}, {new: false}); + { $set: { 'profile.qualified': true } }, { new: false }); return !!myrec; }; -UserSchema.statics.setVerifiedByAportador = async function( - idapp, username, valuebool) { +UserSchema.statics.setVerifiedByAportador = async function ( + idapp, username, valuebool) { const User = this; if (username === undefined) @@ -985,7 +986,7 @@ UserSchema.statics.setVerifiedByAportador = async function( 'username': username, }; - const userver = await User.findOne(myquery, {verified_by_aportador: 1}).lean(); + const userver = await User.findOne(myquery, { verified_by_aportador: 1 }).lean(); let scrivi = true; if (userver) { @@ -993,7 +994,7 @@ UserSchema.statics.setVerifiedByAportador = async function( } if (scrivi) { const myrec = await User.findOneAndUpdate(myquery, - {$set: {'verified_by_aportador': valuebool}}, {new: false}); + { $set: { 'verified_by_aportador': valuebool } }, { new: false }); return !!myrec; } else { @@ -1002,8 +1003,8 @@ UserSchema.statics.setVerifiedByAportador = async function( }; -UserSchema.statics.setnotask_verif = async function( - idapp, username, valuebool) { +UserSchema.statics.setnotask_verif = async function ( + idapp, username, valuebool) { const User = this; if (username === undefined) @@ -1015,13 +1016,13 @@ UserSchema.statics.setnotask_verif = async function( }; const myrec = await User.findOneAndUpdate(myquery, - {$set: {'notask_verif': valuebool}}, {new: false}); + { $set: { 'notask_verif': valuebool } }, { new: false }); return !!myrec; }; -UserSchema.statics.setaportador_solidario = async function( - idapp, username, usernameAportador) { +UserSchema.statics.setaportador_solidario = async function ( + idapp, username, usernameAportador) { const User = this; if (username === undefined) @@ -1033,20 +1034,20 @@ UserSchema.statics.setaportador_solidario = async function( }; const myrec = await User.findOneAndUpdate(myquery, - {$set: {'aportador_solidario': usernameAportador}}, {new: false}); + { $set: { 'aportador_solidario': usernameAportador } }, { new: false }); return !!myrec; }; -UserSchema.statics.setVerifiedByAportadorToALL = async function() { +UserSchema.statics.setVerifiedByAportadorToALL = async function () { - return await User.updateMany({}, {$set: {'verified_by_aportador': true}}, - {new: false}); + return await User.updateMany({}, { $set: { 'verified_by_aportador': true } }, + { new: false }); }; -UserSchema.statics.setUserQualified_2Invitati = async function( - idapp, username) { +UserSchema.statics.setUserQualified_2Invitati = async function ( + idapp, username) { const User = this; if (username === undefined) @@ -1058,7 +1059,7 @@ UserSchema.statics.setUserQualified_2Invitati = async function( }; const myrec = await User.findOneAndUpdate(myquery, - {$set: {'profile.qualified_2invitati': true}}, {new: false}); + { $set: { 'profile.qualified_2invitati': true } }, { new: false }); return !!myrec; }; @@ -1100,27 +1101,27 @@ UserSchema.statics.getnumPaymentOk = function (idapp) { }; */ -UserSchema.statics.getUsersNationalityQuery = function(idapp) { +UserSchema.statics.getUsersNationalityQuery = function (idapp) { const query = [ { $match: { idapp, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, }, { - $group: {_id: '$profile.nationality', count: {$sum: 1}}, + $group: { _id: '$profile.nationality', count: { $sum: 1 } }, }, { - $sort: {count: -1}, + $sort: { count: -1 }, }, ]; return query; }; -UserSchema.statics.getindOrderDuplicate = function(idapp) { +UserSchema.statics.getindOrderDuplicate = function (idapp) { const User = this; return User.aggregate(User.getUsersNationalityQuery(idapp)).then(ris => { @@ -1129,7 +1130,7 @@ UserSchema.statics.getindOrderDuplicate = function(idapp) { }); }; -UserSchema.statics.findByLinkreg = function(idapp, linkreg) { +UserSchema.statics.findByLinkreg = function (idapp, linkreg) { const User = this; return User.findOne({ @@ -1138,7 +1139,7 @@ UserSchema.statics.findByLinkreg = function(idapp, linkreg) { }); }; -UserSchema.statics.AportadorOrig = function(idapp, id) { +UserSchema.statics.AportadorOrig = function (idapp, id) { const User = this; return User.findOne({ @@ -1152,18 +1153,18 @@ UserSchema.statics.AportadorOrig = function(idapp, id) { }); }; -UserSchema.statics.findByLinkTokenforgot = function(idapp, email, tokenforgot) { +UserSchema.statics.findByLinkTokenforgot = function (idapp, email, tokenforgot) { const User = this; return User.findOne({ 'email': email, 'tokenforgot': tokenforgot, - 'date_tokenforgot': {$gte: tools.IncDateNow(-1000 * 60 * 60 * 4)}, // 4 ore fa! + 'date_tokenforgot': { $gte: tools.IncDateNow(-1000 * 60 * 60 * 4) }, // 4 ore fa! 'idapp': idapp, }); }; -UserSchema.statics.createNewRequestPwd = function(idapp, email) { +UserSchema.statics.createNewRequestPwd = function (idapp, email) { const User = this; const sendemail = require('../sendemail'); @@ -1174,7 +1175,7 @@ UserSchema.statics.createNewRequestPwd = function(idapp, email) { } else { // Creo il tokenforgot user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE). - toString(); + toString(); user.date_tokenforgot = new Date(); user.lasttimeonline = new Date(); return await user.save().then(async () => { @@ -1187,19 +1188,19 @@ UserSchema.statics.createNewRequestPwd = function(idapp, email) { }); }; -UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function(idapp, username) { +UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function (idapp, username) { const User = this; const user = await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }); if (user) { // Creo il tokenforgot user.tokenforgot = jwt.sign(user._id.toHexString(), process.env.SIGNCODE). - toString(); + toString(); user.date_tokenforgot = new Date(); user.lasttimeonline = new Date(); @@ -1212,14 +1213,14 @@ UserSchema.statics.createNewRequestPwdByUsernameAndGetLink = async function(idap }; -UserSchema.statics.getifRegTokenIsValid = async function(idapp, tokenreg) { +UserSchema.statics.getifRegTokenIsValid = async function (idapp, tokenreg) { const User = this; let regexp = new RegExp(`^${tokenreg}$`, 'i'); const user = await User.findOne({ idapp, - tokenreg: {$regex: regexp} + tokenreg: { $regex: regexp } }); if (user && user.date_tokenreg) { return user.date_tokenreg > (new Date().getTime()); @@ -1228,13 +1229,13 @@ UserSchema.statics.getifRegTokenIsValid = async function(idapp, tokenreg) { } -UserSchema.statics.createNewReqRegistrationGetLink = async function(idapp, username) { +UserSchema.statics.createNewReqRegistrationGetLink = async function (idapp, username) { const User = this; const user = await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }); if (user) { @@ -1243,14 +1244,14 @@ UserSchema.statics.createNewReqRegistrationGetLink = async function(idapp, usern // Creo il tokenforgot let mycodestr = user._id.toHexString() + new Date().getTime().toString(); user.tokenreg = jwt.sign(mycodestr, process.env.SIGNCODE). - toString(); + toString(); - if (user.tokenreg){ + if (user.tokenreg) { try { user.tokenreg = user.tokenreg.replaceAll('.', ''); user.tokenreg = user.tokenreg.replaceAll('/', ''); user.tokenreg = user.tokenreg.slice(-8); - }catch (e) { + } catch (e) { console.error('err', e); } } @@ -1270,13 +1271,13 @@ UserSchema.statics.createNewReqRegistrationGetLink = async function(idapp, usern }; -UserSchema.statics.findByEmail = function(idapp, email, onlyifVerifiedByAportador) { +UserSchema.statics.findByEmail = function (idapp, email, onlyifVerifiedByAportador) { const User = this; return User.findOne({ 'idapp': idapp, 'email': email, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }).then((rec) => { if (rec && onlyifVerifiedByAportador) { if (tools.getAskToVerifyReg(idapp)) { @@ -1290,16 +1291,16 @@ UserSchema.statics.findByEmail = function(idapp, email, onlyifVerifiedByAportado }); }; -UserSchema.statics.getLastUser = function(idapp) { +UserSchema.statics.getLastUser = function (idapp) { const User = this; return User.findOne({ idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }).sort({index: -1}); + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }).sort({ index: -1 }); }; -UserSchema.statics.findByIndex = function(idapp, index) { +UserSchema.statics.findByIndex = function (idapp, index) { const User = this; try { @@ -1308,15 +1309,15 @@ UserSchema.statics.findByIndex = function(idapp, index) { idapp, index, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }); } catch (e) { console.error(e.message); } }; -UserSchema.statics.findByOldOrder = function(idapp, old_order) { +UserSchema.statics.findByOldOrder = function (idapp, old_order) { const User = this; try { @@ -1324,22 +1325,22 @@ UserSchema.statics.findByOldOrder = function(idapp, old_order) { idapp, old_order, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }); } catch (e) { console.error(e.message); } }; -UserSchema.pre('save', async function(next) { +UserSchema.pre('save', async function (next) { try { if (this.isNew) { try { - const myrec = await User.findOne({idapp: this.idapp}). - limit(1). - sort({index: -1}); + const myrec = await User.findOne({ idapp: this.idapp }). + limit(1). + sort({ index: -1 }); if (!!myrec) { this.index = myrec._doc.index + 1; @@ -1370,22 +1371,22 @@ UserSchema.pre('save', async function(next) { } }); -UserSchema.methods.removeToken = function(token) { +UserSchema.methods.removeToken = function (token) { const user = this; return user.updateOne({ $pull: { - tokens: {token}, + tokens: { token }, }, }); }; -UserSchema.statics.getEmailByUsername = async function(idapp, username) { +UserSchema.statics.getEmailByUsername = async function (idapp, username) { const User = this; return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }).then((arrrec) => { return ((arrrec) ? arrrec.email : ''); }).catch((e) => { @@ -1393,39 +1394,39 @@ UserSchema.statics.getEmailByUsername = async function(idapp, username) { }); }; -UserSchema.statics.getUsernameById = async function(idapp, id) { +UserSchema.statics.getUsernameById = async function (idapp, id) { const User = this; return await User.findOne({ idapp, _id: id, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {username: 1}).then((myuser) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { username: 1 }).then((myuser) => { return ((myuser) ? myuser.username : ''); }).catch((e) => { }); }; -UserSchema.statics.getUserById = function(idapp, id) { +UserSchema.statics.getUserById = function (idapp, id) { const User = this; return User.findOne({ idapp, _id: id, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }); }; -UserSchema.statics.getUserByUsername = function(idapp, username) { +UserSchema.statics.getUserByUsername = function (idapp, username) { const User = this; return User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }); }; -UserSchema.statics.isMyFriend = async function(idapp, username, myusername) { +UserSchema.statics.isMyFriend = async function (idapp, username, myusername) { const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername); if (myfriends) { @@ -1436,8 +1437,8 @@ UserSchema.statics.isMyFriend = async function(idapp, username, myusername) { }; -UserSchema.statics.getUserProfileByUsername = async function( - idapp, username, myusername, usaSuperPower, myperm = '') { +UserSchema.statics.getUserProfileByUsername = async function ( + idapp, username, myusername, usaSuperPower, myperm = '') { const User = this; // If is my Friend, then can show all @@ -1467,6 +1468,7 @@ UserSchema.statics.getUserProfileByUsername = async function( aportador_solidario: 1, name: 1, surname: 1, + lasttimeonline: 1, deleted: 1, sospeso: 1, reported: 1, @@ -1507,6 +1509,7 @@ UserSchema.statics.getUserProfileByUsername = async function( aportador_solidario: 1, name: 1, surname: 1, + lasttimeonline: 1, deleted: 1, sospeso: 1, reported: 1, @@ -1547,6 +1550,7 @@ UserSchema.statics.getUserProfileByUsername = async function( aportador_solidario: 1, name: 1, surname: 1, + lasttimeonline: 1, deleted: 1, sospeso: 1, reported: 1, @@ -1585,11 +1589,11 @@ UserSchema.statics.getUserProfileByUsername = async function( const myfind = { idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }; const query = [ - {$match: myfind}, + { $match: myfind }, { $lookup: { from: 'cities', @@ -1610,8 +1614,8 @@ UserSchema.statics.getUserProfileByUsername = async function( '$match': { '$expr': { $and: [ - {$eq: ['$username', '$$user_name']}, - {$eq: ['$idapp', '$$idapp']}, + { $eq: ['$username', '$$user_name'] }, + { $eq: ['$idapp', '$$idapp'] }, ], }, }, @@ -1622,10 +1626,10 @@ UserSchema.statics.getUserProfileByUsername = async function( }, { $unwind: - { - path: '$useraport', - preserveNullAndEmptyArrays: true, - }, + { + path: '$useraport', + preserveNullAndEmptyArrays: true, + }, }, { @@ -1643,7 +1647,7 @@ UserSchema.statics.getUserProfileByUsername = async function( }, }, }, - {$project: whatToShow}, + { $project: whatToShow }, ]; @@ -1674,15 +1678,15 @@ UserSchema.statics.getUserProfileByUsername = async function( }; -UserSchema.statics.getArrUsernameFromFieldByUsername = async function( - idapp, username, field, subfield) { +UserSchema.statics.getArrUsernameFromFieldByUsername = async function ( + idapp, username, field, subfield) { const myobj = {}; myobj[field + '.' + subfield] = 1; let arrrec = await User.findOne({ idapp, 'username': username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }, myobj).then((ris) => ris ? ris._doc[field][subfield] : []); if (arrrec && arrrec.length > 0) { @@ -1692,79 +1696,79 @@ UserSchema.statics.getArrUsernameFromFieldByUsername = async function( }; -UserSchema.statics.getUsernameReqFriendsByUsername = async function( - idapp, username) { +UserSchema.statics.getUsernameReqFriendsByUsername = async function ( + idapp, username) { return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', - 'req_friends'); + 'req_friends'); }; -UserSchema.statics.getUsernameFriendsByUsername = async function( - idapp, username) { +UserSchema.statics.getUsernameFriendsByUsername = async function ( + idapp, username) { return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', - 'friends'); + 'friends'); }; -UserSchema.statics.getUsernameGroupsByUsername = async function( - idapp, username) { +UserSchema.statics.getUsernameGroupsByUsername = async function ( + idapp, username) { return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', - 'mygroups'); + 'mygroups'); }; -UserSchema.statics.getUsernameCircuitsByUsername = async function( - idapp, username) { +UserSchema.statics.getUsernameCircuitsByUsername = async function ( + idapp, username) { return await this.getArrUsernameFromFieldByUsername(idapp, username, 'profile', - 'mycircuits'); + 'mycircuits'); }; // Rimuovo l'Amicizia -UserSchema.statics.removeFriend = async function( - idapp, username, usernameDest) { - return await User.updateOne({idapp, username}, - {$pull: {'profile.friends': {username: {$in: [usernameDest]}}}}); +UserSchema.statics.removeFriend = async function ( + idapp, username, usernameDest) { + return await User.updateOne({ idapp, username }, + { $pull: { 'profile.friends': { username: { $in: [usernameDest] } } } }); }; // Rimuovo il Gruppo -UserSchema.statics.removeFromMyGroups = async function( - idapp, username, groupnameDest) { - return await User.updateOne({idapp, username}, - {$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}}); +UserSchema.statics.removeFromMyGroups = async function ( + idapp, username, groupnameDest) { + return await User.updateOne({ idapp, username }, + { $pull: { 'profile.mygroups': { groupname: { $in: [groupnameDest] } } } }); }; // Rimuovo il Gruppo -UserSchema.statics.removeFromCircuits = async function(idapp, username, circuitname) { - return await User.updateOne({idapp, username}, - {$pull: {'profile.mycircuits': {circuitname: {$in: [circuitname]}}}}); +UserSchema.statics.removeFromCircuits = async function (idapp, username, circuitname) { + return await User.updateOne({ idapp, username }, + { $pull: { 'profile.mycircuits': { circuitname: { $in: [circuitname] } } } }); }; // Rimuovo il Gruppo per Tutti gli Utenti -UserSchema.statics.removeAllUsersFromMyGroups = async function(idapp, groupnameDest) { - return await User.updateMany({idapp}, - {$pull: {'profile.mygroups': {groupname: {$in: [groupnameDest]}}}}); +UserSchema.statics.removeAllUsersFromMyGroups = async function (idapp, groupnameDest) { + return await User.updateMany({ idapp }, + { $pull: { 'profile.mygroups': { groupname: { $in: [groupnameDest] } } } }); }; // Rimuovo il Circuito per Tutti gli Utenti -UserSchema.statics.removeAllUsersFromMyCircuits = async function(idapp, circuitname) { - return await User.updateMany({idapp}, - {$pull: {'profile.mycircuits': {circuitname: {$in: [circuitname]}}}}); +UserSchema.statics.removeAllUsersFromMyCircuits = async function (idapp, circuitname) { + return await User.updateMany({ idapp }, + { $pull: { 'profile.mycircuits': { circuitname: { $in: [circuitname] } } } }); }; // Rimuovo la Richiesta di Amicizia -UserSchema.statics.removeReqFriend = async function( - idapp, username, usernameDest) { - return await User.updateOne({idapp, username: username}, - {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}}); +UserSchema.statics.removeReqFriend = async function ( + idapp, username, usernameDest) { + return await User.updateOne({ idapp, username: username }, + { $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } }); }; -UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, usernameDest, cmd, value) { +UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value) { - const {SendNotif} = require('../models/sendnotif'); + const { SendNotif } = require('../models/sendnotif'); const telegrambot = require('../telegram/telegrambot'); @@ -1782,11 +1786,11 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user // Aggiungi alle amicizie await this.setFriendsCmd(req, idapp, usernameOrig, usernameDest, - shared_consts.FRIENDSCMD.SETFRIEND, value); + shared_consts.FRIENDSCMD.SETFRIEND, value); - return await User.updateOne({idapp, username: usernameDest}, - {$set: {verified_by_aportador: value, trust_modified: new Date()}}, - {new: false}); + return await User.updateOne({ idapp, username: usernameDest }, + { $set: { verified_by_aportador: value, trust_modified: new Date() } }, + { new: false }); } else if (cmd === shared_consts.FRIENDSCMD.SETFRIEND) { // Aggiungo l'Amicizia a me @@ -1794,9 +1798,9 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user idapp, username: usernameOrig, 'profile.friends': { - $elemMatch: {username: {$eq: usernameDest}}, + $elemMatch: { username: { $eq: usernameDest } }, }, - }, {_id: 1}).lean(); + }, { _id: 1 }).lean(); if (!foundIfAlreadyFriend) { update = { @@ -1807,27 +1811,27 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user }, }, }; - ris = await User.updateOne({idapp, username: usernameOrig}, update); + ris = await User.updateOne({ idapp, username: usernameOrig }, update); // Send a notification to the DESTINATION FRIENDSHIP ! let req = tools.getReqByPar(idapp, usernameOrig); - await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED); + await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED); // Send a notification to the SENDER FRIENDSHIP ! req = tools.getReqByPar(idapp, usernameOrig); - await SendNotif.createNewNotifToSingleUser(req, null, {usernameOrig}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST); + await SendNotif.createNewNotifToSingleUser(req, null, { usernameOrig }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_ACCEPTED_MY_REQUEST); - update = {$pull: {'profile.req_friends': {username: {$in: [usernameDest]}}}}; - ris = await User.updateOne({idapp, username: usernameOrig}, update); + update = { $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } }; + ris = await User.updateOne({ idapp, username: usernameOrig }, update); if (ris) { try { const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest); const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig); - const msgOrig = i18n.__({phrase: '✅ %s accepted your Friendship request !', locale: user.lang}, usernameDest); - const msgDest = i18n.__({phrase: '✅ You have accepted %s\' Friendship request!', locale: userDest.lang}, usernameOrig); + const msgOrig = i18n.__({ phrase: '✅ %s accepted your Friendship request !', locale: user.lang }, usernameDest); + const msgDest = i18n.__({ phrase: '✅ You have accepted %s\' Friendship request!', locale: userDest.lang }, usernameOrig); await telegrambot.sendMsgTelegram(idapp, usernameDest, msgDest); await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgOrig); @@ -1843,9 +1847,9 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user idapp, username: usernameDest, 'profile.friends': { - $elemMatch: {username: {$eq: usernameOrig}}, + $elemMatch: { username: { $eq: usernameOrig } }, }, - }, {_id: 1}).lean(); + }, { _id: 1 }).lean(); if (!foundIfAlreadyFriend2) { update = { @@ -1856,7 +1860,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user }, }, }; - ris = await User.updateOne({idapp, username: usernameDest}, update); + ris = await User.updateOne({ idapp, username: usernameDest }, update); this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo l'Amicizia da me this.removeReqFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da te @@ -1870,9 +1874,9 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user idapp, username: usernameDest, 'profile.req_friends': { - $elemMatch: {username: {$eq: usernameOrig}}, + $elemMatch: { username: { $eq: usernameOrig } }, }, - }, {_id: 1}).lean(); + }, { _id: 1 }).lean(); if (value) { if (!foundIfAlreadyAskFriend) { @@ -1884,7 +1888,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user }, }, }; - ris = await User.updateOne({idapp, username: usernameDest}, update); + ris = await User.updateOne({ idapp, username: usernameDest }, update); } if (ris) { // Invia una notifica alla persona @@ -1913,8 +1917,8 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user // CREATE NOTIFICATION IN TABLE SENDNOTIF const req = tools.getReqByPar(idapp, usernameOrig); - await SendNotif.createNewNotifToSingleUser(req, null, {usernameDest}, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_REFUSED); + await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_REFUSED); await this.removeReqFriend(idapp, usernameDest, usernameOrig); // Rimuovo la Richiesta di Amicizia da lui ris = await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me @@ -1928,7 +1932,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user await this.removeFriend(idapp, usernameOrig, usernameDest); // Rimuovo l'Amicizia da me // Blocco la persona - ris = await User.updateOne({idapp, username: usernameDest}, { + ris = await User.updateOne({ idapp, username: usernameDest }, { $set: { blocked: true, sospeso: true, @@ -1941,7 +1945,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user username_worked = usernameDest; // Segnalo la persona - ris = await User.updateOne({idapp, username: username_worked}, { + ris = await User.updateOne({ idapp, username: username_worked }, { $set: { reported: true, username_who_report: usernameOrig, @@ -1952,22 +1956,22 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user if (ris) { // Send a notification to the DESTINATION! // Sei stato segnalato da %s per comportamenti non idonei. Contatta %s per chiarimenti - await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, - shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_REPORTED); + await SendNotif.createNewNotifToSingleUser(req, null, { username_worked, usernameDest, username_action }, false, + shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_REPORTED); // Send a notification to the SENDER ! // Hai segnalato %s da %s per comportamenti non idonei. - await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false, - shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_REPORTED); + await SendNotif.createNewNotifToSingleUser(req, null, { username_worked, usernameDest: username_action, username_action }, false, + shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_REPORTED); if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) { // Send a notification to the Admin await SendNotif.createNewNotifToSingleUser(req, null, - {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false, - shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_REPORTED); + { username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true }, false, + shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_REPORTED); } } @@ -1976,7 +1980,7 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user username_worked = usernameDest; // Sblocco la persona - ris = await User.updateOne({idapp, username: username_worked}, { + ris = await User.updateOne({ idapp, username: username_worked }, { $set: { reported: false, }, @@ -1984,22 +1988,22 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user if (ris) { // Send a notification to the DESTINATION! - await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest, username_action}, false, - shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED); + await SendNotif.createNewNotifToSingleUser(req, null, { username_worked, usernameDest, username_action }, false, + shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED); // Send a notification to the SENDER ! // Hai segnalato %s da %s per comportamenti non idonei. - await SendNotif.createNewNotifToSingleUser(req, null, {username_worked, usernameDest: username_action, username_action}, false, - shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED); + await SendNotif.createNewNotifToSingleUser(req, null, { username_worked, usernameDest: username_action, username_action }, false, + shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED); if (usernameOrig !== telegrambot.ADMIN_USER_SERVER) { // Send a notification to the Admin await SendNotif.createNewNotifToSingleUser(req, null, - {username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true}, false, - shared_consts.TypeNotifs.TYPEDIR_FRIENDS, - shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED); + { username_worked, usernameDest: telegrambot.ADMIN_USER_SERVER, username_action, isAdmin: true }, false, + shared_consts.TypeNotifs.TYPEDIR_FRIENDS, + shared_consts.TypeNotifs.ID_FRIENDS_UNBLOCKED); } } @@ -2011,56 +2015,56 @@ UserSchema.statics.setFriendsCmd = async function(req, idapp, usernameOrig, user return ris; }; -UserSchema.statics.ifAlreadyInGroup = async function(idapp, usernameOrig, groupnameDest) { +UserSchema.statics.ifAlreadyInGroup = async function (idapp, usernameOrig, groupnameDest) { // Controllo se è stato già inserito return await User.findOne({ idapp, username: usernameOrig, 'profile.mygroups': { - $elemMatch: {groupname: {$eq: groupnameDest}}, + $elemMatch: { groupname: { $eq: groupnameDest } }, }, }).lean(); }; -UserSchema.statics.ifAlreadyInCircuit = async function(idapp, usernameOrig, circuitname) { +UserSchema.statics.ifAlreadyInCircuit = async function (idapp, usernameOrig, circuitname) { // Controllo se è stato già inserito return await User.findOne({ idapp, username: usernameOrig, 'profile.mycircuits': { - $elemMatch: {circuitname: {$eq: circuitname}}, + $elemMatch: { circuitname: { $eq: circuitname } }, }, }).lean(); }; -UserSchema.statics.countUsersInGroup = async function(idapp, groupnameDest) { +UserSchema.statics.countUsersInGroup = async function (idapp, groupnameDest) { // Controllo se è stato già inserito return await User.countDocuments({ idapp, 'profile.mygroups': { - $elemMatch: {groupname: {$eq: groupnameDest}}, + $elemMatch: { groupname: { $eq: groupnameDest } }, }, }); }; -UserSchema.statics.countUsersInCircuit = async function(idapp, circuitname) { +UserSchema.statics.countUsersInCircuit = async function (idapp, circuitname) { // Controllo se è stato già inserito return await User.countDocuments({ idapp, 'profile.mycircuits': { - $elemMatch: {circuitname: {$eq: circuitname}}, + $elemMatch: { circuitname: { $eq: circuitname } }, }, }); }; -UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameDest, cmd, value, username_action) { +UserSchema.statics.setGroupsCmd = async function (idapp, usernameOrig, groupnameDest, cmd, value, username_action) { let ris = null; let update = {}; @@ -2077,15 +2081,15 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD }, }, }; - ris = await User.updateOne({idapp, username: usernameOrig}, update); + ris = await User.updateOne({ idapp, username: usernameOrig }, update); // Elimina la richiesta: - update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}}; - await MyGroup.updateOne({idapp, groupname: groupnameDest}, update); + update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } }; + await MyGroup.updateOne({ idapp, groupname: groupnameDest }, update); // Elimina eventualmente se era bloccato: - update = {$pull: {refused_users: {username: {$in: [usernameOrig]}}}}; - await MyGroup.updateOne({idapp, groupname: groupnameDest}, update); + update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } }; + await MyGroup.updateOne({ idapp, groupname: groupnameDest }, update); } else { ris = false; } @@ -2100,7 +2104,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD idapp, groupname: groupnameDest, 'req_users': { - $elemMatch: {username: {$eq: usernameOrig}}, + $elemMatch: { username: { $eq: usernameOrig } }, }, }); @@ -2114,8 +2118,8 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD }, }, }; - ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, - update); + ris = await MyGroup.updateOne({ idapp, groupname: groupnameDest }, + update); } if (ris) { // Invia una notifica alla persona @@ -2172,7 +2176,7 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD await User.removeFromMyGroups(idapp, usernameOrig, groupnameDest); // Rimuovo l'Amicizia da me // Blocco il Gruppo - ris = await MyGroup.updateOne({idapp, groupname: groupnameDest}, { + ris = await MyGroup.updateOne({ idapp, groupname: groupnameDest }, { $set: { blocked: true, username_who_block: usernameOrig, @@ -2202,11 +2206,11 @@ UserSchema.statics.setGroupsCmd = async function(idapp, usernameOrig, groupnameD return ris; }; -UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitname, cmd, value, username_action, extrarec) { +UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitname, cmd, value, username_action, extrarec) { // console.log('setCircuitCmd', cmd); - const {SendNotif} = require('../models/sendnotif'); + const { SendNotif } = require('../models/sendnotif'); let ris = null; let outres = { @@ -2226,15 +2230,15 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna }, }, }; - ris = await User.updateOne({idapp, username: usernameOrig}, update); + ris = await User.updateOne({ idapp, username: usernameOrig }, update); // Elimina la richiesta: - update = {$pull: {req_users: {username: {$in: [usernameOrig]}}}}; - await Circuit.updateOne({idapp, name: circuitname}, update); + update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } }; + await Circuit.updateOne({ idapp, name: circuitname }, update); // Elimina eventualmente se era bloccato: - update = {$pull: {refused_users: {username: {$in: [usernameOrig]}}}}; - await Circuit.updateOne({idapp, name: circuitname}, update); + update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } }; + await Circuit.updateOne({ idapp, name: circuitname }, update); await Account.createAccount(idapp, usernameOrig, circuitname); @@ -2255,7 +2259,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna idapp, name: circuitname, 'req_users': { - $elemMatch: {username: {$eq: usernameOrig}}, + $elemMatch: { username: { $eq: usernameOrig } }, }, }); @@ -2269,7 +2273,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna }, }, }; - ris = await Circuit.updateOne({idapp, name: circuitname}, update); + ris = await Circuit.updateOne({ idapp, name: circuitname }, update); } if (ris) { @@ -2344,7 +2348,7 @@ UserSchema.statics.setCircuitCmd = async function(idapp, usernameOrig, circuitna if (outres.cansend) { // Invia una notifica di moneta alla persona const out = await tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, false, true, username_action, - extrarec); + extrarec); if (out) outres.result = out.ris; } else { @@ -2429,6 +2433,7 @@ function getWhatToShow(idapp, username) { aportador_solidario: 1, name: 1, surname: 1, + lasttimeonline: 1, deleted: 1, sospeso: 1, reported: 1, @@ -2481,7 +2486,7 @@ function getWhatToShow_Unknown(idapp, username) { } -UserSchema.statics.getWhatToShow_IfFriends = async function(idapp, username) { +UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) { return { username: 1, aportador_solidario: 1, @@ -2506,41 +2511,41 @@ UserSchema.statics.getWhatToShow_IfFriends = async function(idapp, username) { }; -UserSchema.statics.getInfoFriendByUsername = async function(idapp, username) { +UserSchema.statics.getInfoFriendByUsername = async function (idapp, username) { const whatToShow = getWhatToShow(idapp, username); return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }, whatToShow).lean().then((rec) => !!rec ? rec : null); }; -UserSchema.statics.getInfoAskFriendByUsername = async function( - idapp, username) { +UserSchema.statics.getInfoAskFriendByUsername = async function ( + idapp, username) { const whatToShow = getWhatToShow_Unknown(idapp, username); return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }, whatToShow).lean().then((rec) => !!rec ? rec : null); }; -UserSchema.statics.getAskedFriendsByUsername = async function(idapp, username) { +UserSchema.statics.getAskedFriendsByUsername = async function (idapp, username) { const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username); return await User.find({ idapp, 'profile.req_friends': { - $elemMatch: {username: {$eq: username}}, + $elemMatch: { username: { $eq: username } }, }, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }, whatToShow_Unknown).then((rec) => { //return rec.map(m => m.username); @@ -2548,48 +2553,48 @@ UserSchema.statics.getAskedFriendsByUsername = async function(idapp, username) { }; -UserSchema.statics.getFriendsByUsername = async function(idapp, username) { +UserSchema.statics.getFriendsByUsername = async function (idapp, username) { try { const whatToShow = getWhatToShow(idapp, username); const whatToShow_Unknown = getWhatToShow_Unknown(idapp, username); const arrUsernameFriends = await User.getUsernameFriendsByUsername(idapp, - username); + username); const arrUsernameReqFriends = await User.getUsernameReqFriendsByUsername( - idapp, username); + idapp, username); let listFriends = await User.find({ idapp, - username: {$in: arrUsernameFriends}, + username: { $in: arrUsernameFriends }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, whatToShow); let listRequestFriends = await User.find({ idapp, - username: {$in: arrUsernameReqFriends}, + username: { $in: arrUsernameReqFriends }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, whatToShow_Unknown); let listSentRequestFriends = await User.find({ idapp, 'profile.req_friends': { - $elemMatch: {username: {$eq: username}}, + $elemMatch: { username: { $eq: username } }, }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, whatToShow_Unknown); let listTrusted = await User.find({ idapp, aportador_solidario: username, - 'profile.teleg_id': {$gt: 0}, + 'profile.teleg_id': { $gt: 0 }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, whatToShow); return { @@ -2612,13 +2617,13 @@ UserSchema.statics.getFriendsByUsername = async function(idapp, username) { }; }; -UserSchema.statics.getAportadorSolidarioByUsername = async function( - idapp, username) { +UserSchema.statics.getAportadorSolidarioByUsername = async function ( + idapp, username) { const User = this; return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }).then((rec) => { return ((rec) ? rec.aportador_solidario : ''); }).catch((e) => { @@ -2626,12 +2631,12 @@ UserSchema.statics.getAportadorSolidarioByUsername = async function( }); }; -UserSchema.statics.UserByIdTelegram = async function(idapp, teleg_id) { +UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) { const User = this; return await User.findOne({ idapp, 'profile.teleg_id': teleg_id, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }).lean().then((rec) => { return (!!rec) ? rec : null; }).catch((e) => { @@ -2639,12 +2644,12 @@ UserSchema.statics.UserByIdTelegram = async function(idapp, teleg_id) { }); }; -UserSchema.statics.UsersByIdTelegram = async function(idapp, teleg_id) { +UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) { const User = this; return await User.find({ idapp, 'profile.teleg_id': teleg_id, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }).lean().then((rec) => { return (!!rec) ? rec : null; }).catch((e) => { @@ -2652,7 +2657,7 @@ UserSchema.statics.UsersByIdTelegram = async function(idapp, teleg_id) { }); }; -UserSchema.statics.setPicProfile = async function(idapp, username, imgpic) { +UserSchema.statics.setPicProfile = async function (idapp, username, imgpic) { const User = this; const fields_to_update = { @@ -2661,44 +2666,44 @@ UserSchema.statics.setPicProfile = async function(idapp, username, imgpic) { return await User.findOneAndUpdate({ idapp, username, - }, {$set: fields_to_update}, {new: false}).lean().then((record) => { + }, { $set: fields_to_update }, { new: false }).lean().then((record) => { return !!record; }); }; -UserSchema.statics.TelegIdByUsername = async function(idapp, username) { +UserSchema.statics.TelegIdByUsername = async function (idapp, username) { const User = this; return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {'profile.teleg_id': 1}).lean().then((rec) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { 'profile.teleg_id': 1 }).lean().then((rec) => { return (!!rec) ? rec.profile.teleg_id : null; }).catch((e) => { console.error('TelegIdByUsername', e); }); }; -UserSchema.statics.TelegIdById = async function(idapp, id) { +UserSchema.statics.TelegIdById = async function (idapp, id) { const User = this; return await User.findOne({ idapp, _id: id, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {'profile.teleg_id': 1}).lean().then((rec) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { 'profile.teleg_id': 1 }).lean().then((rec) => { return (!!rec) ? rec.profile.teleg_id : null; }).catch((e) => { console.error('TelegIdByUsername', e); }); }; -UserSchema.statics.notAsk_VerifByUsername = async function(idapp, username) { +UserSchema.statics.notAsk_VerifByUsername = async function (idapp, username) { return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {'notask_verif': 1}).lean().then((rec) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { 'notask_verif': 1 }).lean().then((rec) => { return (!!rec && rec.notask_verif) ? true : false; }).catch((e) => { console.error('notAsk_VerifByUsername', e); @@ -2706,8 +2711,8 @@ UserSchema.statics.notAsk_VerifByUsername = async function(idapp, username) { }); }; -UserSchema.statics.SetTelegramCheckCode = async function( - idapp, id, teleg_checkcode) { +UserSchema.statics.SetTelegramCheckCode = async function ( + idapp, id, teleg_checkcode) { const User = this; const fields_to_update = { @@ -2716,13 +2721,13 @@ UserSchema.statics.SetTelegramCheckCode = async function( return await User.findOneAndUpdate({ _id: id, - }, {$set: fields_to_update}, {new: false}).lean().then((record) => { + }, { $set: fields_to_update }, { new: false }).lean().then((record) => { return !!record; }); }; -UserSchema.statics.NonVoglioImbarcarmi = async function(idapp, username) { +UserSchema.statics.NonVoglioImbarcarmi = async function (idapp, username) { const User = this; const fields_to_update = { @@ -2732,13 +2737,13 @@ UserSchema.statics.NonVoglioImbarcarmi = async function(idapp, username) { return await User.findOneAndUpdate({ idapp, username, - }, {$set: fields_to_update}, {new: false}).then((record) => { + }, { $set: fields_to_update }, { new: false }).then((record) => { return !!record; }); }; -UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) { +UserSchema.statics.SetTelegramIdSuccess = async function (idapp, id, teleg_id) { const User = this; const fields_to_update = { @@ -2750,7 +2755,7 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) { return await User.findOneAndUpdate({ idapp, _id: id, - }, {$set: fields_to_update}, {new: false}).lean().then((record) => { + }, { $set: fields_to_update }, { new: false }).lean().then((record) => { if (record) { return User.findOne({ @@ -2764,9 +2769,9 @@ UserSchema.statics.SetTelegramIdSuccess = async function(idapp, id, teleg_id) { }; -UserSchema.statics.getUsernameTelegram = async function(idapp, username) { +UserSchema.statics.getUsernameTelegram = async function (idapp, username) { const User = this; - return await User.findOne({idapp, username}, {'profile.username_telegram': 1}).lean().then((ris) => { + return await User.findOne({ idapp, username }, { 'profile.username_telegram': 1 }).lean().then((ris) => { if (ris) return ris.profile.username_telegram; else @@ -2774,8 +2779,8 @@ UserSchema.statics.getUsernameTelegram = async function(idapp, username) { }); }; -UserSchema.statics.setUsernameTelegram = async function( - idapp, id, username_telegram, firstname_telegram, lastname_telegram) { +UserSchema.statics.setUsernameTelegram = async function ( + idapp, id, username_telegram, firstname_telegram, lastname_telegram) { const User = this; const fields_to_update = { @@ -2787,13 +2792,13 @@ UserSchema.statics.setUsernameTelegram = async function( return await User.findOneAndUpdate({ idapp, _id: id, - }, {$set: fields_to_update}, {new: false}).then((record) => { + }, { $set: fields_to_update }, { new: false }).then((record) => { return record; }); }; -UserSchema.statics.SetLang = async function(idapp, id, lang) { +UserSchema.statics.SetLang = async function (idapp, id, lang) { const User = this; const fields_to_update = { @@ -2802,13 +2807,13 @@ UserSchema.statics.SetLang = async function(idapp, id, lang) { return await User.findOneAndUpdate({ _id: id, - }, {$set: fields_to_update}, {new: false}).then((record) => { + }, { $set: fields_to_update }, { new: false }).then((record) => { return record; }); }; -UserSchema.statics.SetTelegramWasBlocked = async function(idapp, teleg_id) { +UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) { const User = this; const fields_to_update = { @@ -2821,21 +2826,21 @@ UserSchema.statics.SetTelegramWasBlocked = async function(idapp, teleg_id) { const ris = await User.findOneAndUpdate({ idapp, 'profile.teleg_id': teleg_id, - }, {$set: fields_to_update}, {new: false}).then((record) => { + }, { $set: fields_to_update }, { new: false }).then((record) => { return record; }); } }; -UserSchema.statics.getNameSurnameByUsername = async function( - idapp, username, reale = false) { +UserSchema.statics.getNameSurnameByUsername = async function ( + idapp, username, reale = false) { const User = this; return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {username: 1, name: 1, surname: 1}).then((rec) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { username: 1, name: 1, surname: 1 }).then((rec) => { let ris = rec.username; if (!!rec) { if (reale) { @@ -2855,23 +2860,23 @@ UserSchema.statics.getNameSurnameByUsername = async function( }); }; -UserSchema.statics.getIdByUsername = async function(idapp, username) { +UserSchema.statics.getIdByUsername = async function (idapp, username) { const User = this; let regexp = new RegExp(`^${username}$`, 'i'); return await User.findOne({ idapp, - username: {$regex: regexp}, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {username: 1, _id: 1}).then((rec) => { + username: { $regex: regexp }, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { username: 1, _id: 1 }).then((rec) => { return (!!rec) ? rec._id.toString() : ''; }).catch((e) => { console.error('getIdByUsername', e); }); }; -UserSchema.statics.getRealUsernameByUsername = async function(idapp, username) { +UserSchema.statics.getRealUsernameByUsername = async function (idapp, username) { const User = this; let regexp = new RegExp(`^${username}$`, 'i'); @@ -2879,133 +2884,133 @@ UserSchema.statics.getRealUsernameByUsername = async function(idapp, username) { return await User.findOne({ idapp, username: - {$regex: regexp}, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {username: 1, _id: 1}).then((rec) => { + { $regex: regexp }, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { username: 1, _id: 1 }).then((rec) => { return (!!rec) ? rec.username : ''; }).catch((e) => { console.error('getRealUsernameByUsername', e); }); }; -UserSchema.statics.getRecLangAndIdByUsername = async function(idapp, username) { +UserSchema.statics.getRecLangAndIdByUsername = async function (idapp, username) { const User = this; return await User.findOne({ idapp, username, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {lang: 1, _id: 1}).then((rec) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { lang: 1, _id: 1 }).then((rec) => { return (!!rec) ? rec : null; }).catch((e) => { console.error('getRecLangAndIdByUsername', e); }); }; -UserSchema.statics.getNameSurnameById = async function(idapp, userId) { +UserSchema.statics.getNameSurnameById = async function (idapp, userId) { const User = this; return await User.findOne({ idapp, _id: userId, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, {name: 1, surname: 1}).then((rec) => { + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, { name: 1, surname: 1 }).then((rec) => { return (!!rec) ? `${rec.name} ${rec.surname}` : ''; }).catch((e) => { console.error('getNameSurnameById', e); }); }; -UserSchema.statics.getusersManagers = async function(idapp) { +UserSchema.statics.getusersManagers = async function (idapp) { const User = this; - return await User.find({idapp, 'profile.manage_telegram': true}, - {username: 1, 'profile.teleg_id': 1, perm: 1}).then((arrrec) => { - return (!!arrrec) ? arrrec : null; - }).catch((e) => { - console.error('getusersManagers', e); - }); + return await User.find({ idapp, 'profile.manage_telegram': true }, + { username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => { + return (!!arrrec) ? arrrec : null; + }).catch((e) => { + console.error('getusersManagers', e); + }); }; -UserSchema.statics.getusersRespList = async function(idapp) { +UserSchema.statics.getusersRespList = async function (idapp) { const User = this; - return await User.find({idapp, 'profile.resplist': true}, - {_id: 1, username: 1, name: 1, surname: 1}).then((arrrec) => { - return (!!arrrec) ? arrrec : null; - }).catch((e) => { - console.error('getusersRespList', e); - }); + return await User.find({ idapp, 'profile.resplist': true }, + { _id: 1, username: 1, name: 1, surname: 1 }).then((arrrec) => { + return (!!arrrec) ? arrrec : null; + }).catch((e) => { + console.error('getusersRespList', e); + }); }; -UserSchema.statics.getusersWorkersList = async function(idapp) { +UserSchema.statics.getusersWorkersList = async function (idapp) { const User = this; - return await User.find({idapp, 'profile.workerslist': true}, - {_id: 1, username: 1, name: 1, surname: 1}).then((arrrec) => { - return (!!arrrec) ? arrrec : null; - }).catch((e) => { - console.error('getusersWorkersList', e); - }); + return await User.find({ idapp, 'profile.workerslist': true }, + { _id: 1, username: 1, name: 1, surname: 1 }).then((arrrec) => { + return (!!arrrec) ? arrrec : null; + }).catch((e) => { + console.error('getusersWorkersList', e); + }); }; -UserSchema.statics.getusersManagersAndZoomeri = async function(idapp) { +UserSchema.statics.getusersManagersAndZoomeri = async function (idapp) { const User = this; return await User.find( - { - idapp, - or: [ - {'profile.manage_telegram': true}, + { + idapp, + or: [ + { 'profile.manage_telegram': true }, + { + perm: { - perm: - { - $bit: + $bit: - Number(shared_consts.Permissions.Zoomeri), + Number(shared_consts.Permissions.Zoomeri), - }, }, - ], - }, - {'profile.teleg_id': 1}).then((arrrec) => { - return (!!arrrec) ? arrrec : null; - }).catch((e) => { - console.error('getusersManagers', e); - }); + }, + ], + }, + { 'profile.teleg_id': 1 }).then((arrrec) => { + return (!!arrrec) ? arrrec : null; + }).catch((e) => { + console.error('getusersManagers', e); + }); }; -UserSchema.statics.getUsersTelegALL = async function(idapp, username) { +UserSchema.statics.getUsersTelegALL = async function (idapp, username) { const User = this; if (!!username) { - return await User.find({idapp, username, 'profile.teleg_id': {$gt: 0}}).lean(); + return await User.find({ idapp, username, 'profile.teleg_id': { $gt: 0 } }).lean(); then((arrrec) => { return (!!arrrec) ? arrrec : null; }). - catch((e) => { - console.error('getUsersTelegALL', e); - }); + catch((e) => { + console.error('getUsersTelegALL', e); + }); } else { - return await User.find({idapp, 'profile.teleg_id': {$gt: 0}}). - lean(). - then((arrrec) => { - return (!!arrrec) ? arrrec : null; - }). - catch((e) => { - console.error('getUsersTelegALL', e); - }); + return await User.find({ idapp, 'profile.teleg_id': { $gt: 0 } }). + lean(). + then((arrrec) => { + return (!!arrrec) ? arrrec : null; + }). + catch((e) => { + console.error('getUsersTelegALL', e); + }); } }; -UserSchema.statics.isManagerByIdTeleg = async function(idapp, idtelegram) { +UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) { const User = this; return await User.findOne({ idapp, 'profile.manage_telegram': true, 'profile.teleg_id': idtelegram, - }, {'profile.teleg_id': 1}).then((rec) => { + }, { 'profile.teleg_id': 1 }).then((rec) => { return (!!rec && rec.profile.teleg_id === idtelegram); }).catch((e) => { console.error('getusersManagers', e); @@ -3013,7 +3018,7 @@ UserSchema.statics.isManagerByIdTeleg = async function(idapp, idtelegram) { }); }; -UserSchema.statics.isAdminByIdTeleg = async function(idapp, idtelegram) { +UserSchema.statics.isAdminByIdTeleg = async function (idapp, idtelegram) { const User = this; return await User.findOne({ @@ -3021,7 +3026,7 @@ UserSchema.statics.isAdminByIdTeleg = async function(idapp, idtelegram) { username: 'paoloar77', 'profile.manage_telegram': true, 'profile.teleg_id': idtelegram, - }, {'profile.teleg_id': 1}).then((rec) => { + }, { 'profile.teleg_id': 1 }).then((rec) => { return (!!rec && rec.profile.teleg_id === idtelegram); }).catch((e) => { console.error('getusersManagers', e); @@ -3029,25 +3034,26 @@ UserSchema.statics.isAdminByIdTeleg = async function(idapp, idtelegram) { }); }; -UserSchema.statics.getUsersList = function(idapp) { +UserSchema.statics.getUsersList = function (idapp) { const User = this; return User.find({ - 'idapp': idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }, - { - username: 1, - name: 1, - surname: 1, - verified_email: 1, - verified_by_aportador: 1, - made_gift: 1, - perm: 1, - email: 1, - date_reg: 1, - img: 1, - }, + 'idapp': idapp, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }, + { + username: 1, + name: 1, + surname: 1, + lasttimeonline: 1, + verified_email: 1, + verified_by_aportador: 1, + made_gift: 1, + perm: 1, + email: 1, + date_reg: 1, + img: 1, + }, ); }; @@ -3056,56 +3062,56 @@ UserSchema.statics.getUsersList = function(idapp) { * @returns {Object} Object -> `{ rows, count }` */ -UserSchema.statics.getFieldsForSearch = function() { +UserSchema.statics.getFieldsForSearch = function () { return [ - {field: 'username', type: tools.FieldType.string}, - {field: 'name', type: tools.FieldType.string}, - {field: 'index', type: tools.FieldType.number}, - {field: 'ind_order', type: tools.FieldType.number}, - {field: 'old_order', type: tools.FieldType.number}, - {field: 'surname', type: tools.FieldType.string}, - {field: 'email', type: tools.FieldType.string}, - {field: 'profile.cell', type: tools.FieldType.string}, - {field: 'profile.email_paypal', type: tools.FieldType.string}, - {field: 'profile.payeer_id', type: tools.FieldType.string}, - {field: 'profile.advcash_id', type: tools.FieldType.string}, - {field: 'profile.revolut', type: tools.FieldType.string}, - {field: 'profile.link_payment', type: tools.FieldType.string}, - {field: 'profile.teleg_id', type: tools.FieldType.number}, - {field: 'profile.username_telegram', type: tools.FieldType.string}, - {field: 'ipaddr', type: tools.FieldType.string}, + { field: 'username', type: tools.FieldType.string }, + { field: 'name', type: tools.FieldType.string }, + { field: 'index', type: tools.FieldType.number }, + { field: 'ind_order', type: tools.FieldType.number }, + { field: 'old_order', type: tools.FieldType.number }, + { field: 'surname', type: tools.FieldType.string }, + { field: 'email', type: tools.FieldType.string }, + { field: 'profile.cell', type: tools.FieldType.string }, + { field: 'profile.email_paypal', type: tools.FieldType.string }, + { field: 'profile.payeer_id', type: tools.FieldType.string }, + { field: 'profile.advcash_id', type: tools.FieldType.string }, + { field: 'profile.revolut', type: tools.FieldType.string }, + { field: 'profile.link_payment', type: tools.FieldType.string }, + { field: 'profile.teleg_id', type: tools.FieldType.number }, + { field: 'profile.username_telegram', type: tools.FieldType.string }, + { field: 'ipaddr', type: tools.FieldType.string }, ]; //{field: 'aportador_solidario', type: tools.FieldType.string} }; -UserSchema.statics.getFieldsForSearchUserFriend = function() { - return [{field: 'username', type: tools.FieldType.exact}]; +UserSchema.statics.getFieldsForSearchUserFriend = function () { + return [{ field: 'username', type: tools.FieldType.exact }]; }; -UserSchema.statics.getFieldsForSearchUserFriend_AllWords = function() { - return [{field: 'username', type: tools.FieldType.string}]; +UserSchema.statics.getFieldsForSearchUserFriend_AllWords = function () { + return [{ field: 'username', type: tools.FieldType.string }]; }; -UserSchema.statics.executeQueryTable = function(idapp, params) { +UserSchema.statics.executeQueryTable = function (idapp, params) { params.fieldsearch = this.getFieldsForSearch(); if (params.options) { if (tools.isBitActive(params.options, - shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) { + shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) { params.fieldsearch = this.getFieldsForSearchUserFriend(); } else if (tools.isBitActive(params.options, - shared_consts.OPTIONS_SEARCH_USER_ALL_WORDS)) { + shared_consts.OPTIONS_SEARCH_USER_ALL_WORDS)) { params.fieldsearch = this.getFieldsForSearchUserFriend_AllWords(); } } return tools.executeQueryTable(this, idapp, params); }; -UserSchema.statics.findAllIdApp = async function(idapp) { +UserSchema.statics.findAllIdApp = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }; return await User.find(myfind, (err, arrrec) => { @@ -3113,14 +3119,14 @@ UserSchema.statics.findAllIdApp = async function(idapp) { }); }; -UserSchema.statics.DuplicateAllRecords = async function(idapporig, idappdest) { +UserSchema.statics.DuplicateAllRecords = async function (idapporig, idappdest) { return await tools.DuplicateAllRecords(this, idapporig, idappdest); }; -UserSchema.statics.getDashboard = async function( - idapp, aportador_solidario, username, aportador_solidario_nome_completo) { +UserSchema.statics.getDashboard = async function ( + idapp, aportador_solidario, username, aportador_solidario_nome_completo) { try { // DATA: username, name, surname, email, intcode_cell, cell @@ -3134,13 +3140,13 @@ UserSchema.statics.getDashboard = async function( dashboard.myself = await User.getUserShortDataByUsername(idapp, username); // Data of my Aportador dashboard.aportador = await User.getUserShortDataByUsername(idapp, - aportador_solidario); + aportador_solidario); // if (dashboard.aportador === undefined) { // dashboard.aportador = await ExtraList.getUserNotRegisteredByNameSurname(idapp, aportador_solidario_nome_completo); // } const arrap = await User.getDownlineByUsername(idapp, username, false, - true); + true); if (!!arrap) dashboard.numpeople_aportador = arrap.length; @@ -3153,8 +3159,8 @@ UserSchema.statics.getDashboard = async function( } }; -UserSchema.statics.getDownline = async function( - idapp, aportador_solidario, username) { +UserSchema.statics.getDownline = async function ( + idapp, aportador_solidario, username) { try { // DATA: username, name, surname, email, intcode_cell, cell @@ -3173,11 +3179,11 @@ UserSchema.statics.getDownline = async function( for (const down of downline.downline) { downline.downbyuser[down.username] = await User.getDownlineByUsername( - idapp, down.username, false); + idapp, down.username, false); for (const down2 of downline.downbyuser[down.username]) { downline.downbyuser[down2.username] = await User.getDownlineByUsername( - idapp, down2.username, false); + idapp, down2.username, false); } } @@ -3208,8 +3214,8 @@ UserSchema.statics.fixUsername = async function (idapp, aportador_solidario_ind_ }; */ -UserSchema.statics.findByCellAndNameSurname = function( - idapp, cell, name, surname) { +UserSchema.statics.findByCellAndNameSurname = function ( + idapp, cell, name, surname) { const User = this; return User.findOne({ @@ -3217,31 +3223,46 @@ UserSchema.statics.findByCellAndNameSurname = function( 'profile.cell': cell, 'name': name, 'surname': surname, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }); }; -UserSchema.statics.getUsersRegistered = async function(idapp) { +UserSchema.statics.getUsersRegistered = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }; return await User.count(myfind); }; -UserSchema.statics.getUsersOnLineToday = async function(idapp) { +UserSchema.statics.getUsersRegisteredToday = async function (idapp) { const User = this; let starttoday = new Date(); - starttoday.setHours(6, 0, 0, 0); + starttoday.setHours(0, 0, 0, 0); const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - lasttimeonline: {$gt: starttoday}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + date_reg: { $gt: starttoday }, + }; + + return await User.count(myfind); +}; + +UserSchema.statics.getUsersOnLineToday = async function (idapp) { + const User = this; + + let starttoday = new Date(); + starttoday.setHours(0, 0, 0, 0); + + const myfind = { + idapp, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + lasttimeonline: { $gt: starttoday }, }; return await User.count(myfind); @@ -3304,158 +3325,186 @@ UserSchema.statics.getUsersQualified = async function (idapp, numinvitati) { // // }; -UserSchema.statics.getEmailNotVerified = async function(idapp) { +UserSchema.statics.getEmailNotVerified = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], verified_email: false, }; return await User.count(myfind); }; -UserSchema.statics.getUsersTelegramAttivo = async function(idapp) { +UserSchema.statics.getUsersTelegramAttivo = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - 'profile.teleg_id': {$gt: 0}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + 'profile.teleg_id': { $gt: 0 }, }; return await User.count(myfind); }; -UserSchema.statics.getUsersAutorizzati = async function(idapp) { +UserSchema.statics.getUsersAutorizzati = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - 'profile.teleg_id': {$gt: 0}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + 'profile.teleg_id': { $gt: 0 }, verified_by_aportador: true, }; return await User.count(myfind); }; -UserSchema.statics.getUsersAutorizzare = async function(idapp) { +UserSchema.statics.getUsersAutorizzare = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - 'profile.teleg_id': {$gt: 0}, - verified_by_aportador: {$exists: false}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + 'profile.teleg_id': { $gt: 0 }, + verified_by_aportador: { $exists: false }, }; return await User.count(myfind); }; -UserSchema.statics.getUsersTelegramPending = async function(idapp) { +UserSchema.statics.getUsersTelegramPending = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - 'profile.teleg_checkcode': {$gt: 0}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + 'profile.teleg_checkcode': { $gt: 0 }, }; return await User.count(myfind); }; -UserSchema.statics.getNumUsers = async function(idapp) { +UserSchema.statics.getNumUsers = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], }; return await User.count(myfind); }; -UserSchema.statics.getUsersZoom = async function(idapp) { +UserSchema.statics.getUsersZoom = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], 'profile.saw_zoom_presentation': true, }; return await User.count(myfind); }; -UserSchema.statics.getUsersResidenti = async function(idapp) { +UserSchema.statics.getUsersResidenti = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - 'profile.socioresidente': {$exists: true, $eq: true}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + 'profile.socioresidente': { $exists: true, $eq: true }, }; - return await User.find(myfind, {username: 1, name: 1, surname: 1}); + return await User.find(myfind, { username: 1, name: 1, surname: 1 }); }; -UserSchema.statics.getSaw_and_Accepted = async function(idapp) { +UserSchema.statics.getSaw_and_Accepted = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], 'profile.saw_and_accepted': shared_consts.ALL_SAW_AND_ACCEPTED, }; return await User.count(myfind); }; -UserSchema.statics.getUsersDreams = async function(idapp) { +UserSchema.statics.getUsersDreams = async function (idapp) { const User = this; const myfind = { idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - 'profile.my_dream': {$exists: true}, - '$expr': {'$gt': [{'$strLenCP': '$profile.my_dream'}, 10]}, + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + 'profile.my_dream': { $exists: true }, + '$expr': { '$gt': [{ '$strLenCP': '$profile.my_dream' }, 10] }, }; return await User.count(myfind); }; -UserSchema.statics.getLastUsers = async function(idapp) { +UserSchema.statics.getLastUsers = async function (idapp) { const User = this; const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5); return await User.find( - { - idapp, - $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], - }, - { - username: 1, - name: 1, - surname: 1, - date_reg: 1, - index: 1, - 'profile.nationality': 1, - }).sort({date_reg: -1}).limit(lastn).then((arr) => { - //return JSON.stringify(arr) - return arr; - }); + { + idapp, + $or: [ + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], + }, + { + username: 1, + name: 1, + surname: 1, + lasttimeonline: 1, + 'profile.img': 1, + date_reg: 1, + index: 1, + 'profile.nationality': 1, + }).sort({ date_reg: -1 }).limit(lastn).then((arr) => { + //return JSON.stringify(arr) + return arr; + }); }; -UserSchema.statics.checkUser = async function(idapp, username) { +UserSchema.statics.getLastOnlineUsers = async function (idapp) { const User = this; - return await User.findOne({idapp, username}, { + const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_ONLINE_USERS', 10); + + return await User.find( + { + idapp, + $or: [ + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], + }, + { + username: 1, + name: 1, + surname: 1, + lasttimeonline: 1, + 'profile.img': 1, + index: 1, + }).sort({ lasttimeonline: -1 }).limit(lastn).then((arr) => { + //return JSON.stringify(arr) + return arr; + }); + +}; + +UserSchema.statics.checkUser = async function (idapp, username) { + const User = this; + + return await User.findOne({ idapp, username }, { verified_email: 1, verified_by_aportador: 1, notask_verif: 1, @@ -3467,22 +3516,22 @@ UserSchema.statics.checkUser = async function(idapp, username) { }; -UserSchema.statics.calculateStat = async function(idapp, username) { +UserSchema.statics.calculateStat = async function (idapp, username) { const User = this; try { - const {MySkill} = require('../models/myskill'); - const {MyGood} = require('../models/mygood'); - const {MyBacheca} = require('../models/mybacheca'); - const {MyGroup} = require('../models/mygroup'); + const { MySkill } = require('../models/myskill'); + const { MyGood } = require('../models/mygood'); + const { MyBacheca } = require('../models/mybacheca'); + const { MyGroup } = require('../models/mygroup'); const numUsersReg = await User.countDocuments( - { - idapp, - $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], - }); + { + idapp, + $or: [ + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], + }); let numByTab = {}; @@ -3491,38 +3540,38 @@ UserSchema.statics.calculateStat = async function(idapp, username) { for (let table of shared_consts.TABLES_VISU_STAT_IN_HOME) { let mytable = globalTables.getTableByTableName(table); if (mytable) { - numByTab[table] = await mytable.countDocuments({idapp}); + numByTab[table] = await mytable.countDocuments({ idapp }); } } - return {numByTab, numUsersReg}; + return { numByTab, numUsersReg }; } catch (e) { console.error(e.message); } }; -UserSchema.statics.getDistinctNationalityQuery = function(idapp) { +UserSchema.statics.getDistinctNationalityQuery = function (idapp) { const query = [ { $match: { idapp, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, }, { - $group: {_id: '$profile.nationality', count: {$sum: 1}}, + $group: { _id: '$profile.nationality', count: { $sum: 1 } }, }, { - $sort: {count: -1}, + $sort: { count: -1 }, }, ]; return query; }; -UserSchema.statics.findAllDistinctNationality = async function(idapp) { +UserSchema.statics.findAllDistinctNationality = async function (idapp) { const User = this; return await User.aggregate(User.getDistinctNationalityQuery(idapp)).then(ris => { @@ -3531,16 +3580,16 @@ UserSchema.statics.findAllDistinctNationality = async function(idapp) { }); }; -UserSchema.statics.getUsersRegDaily = function(idapp, nrec) { +UserSchema.statics.getUsersRegDaily = function (idapp, nrec) { const query = [ { $match: { idapp, - date_reg: {$gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec))}, + date_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, }, { @@ -3552,26 +3601,26 @@ UserSchema.statics.getUsersRegDaily = function(idapp, nrec) { timezone: 'Europe/Rome', }, }, - count: {$sum: 1}, + count: { $sum: 1 }, }, }, { - $sort: {_id: 1}, + $sort: { _id: 1 }, }, ]; return query; }; -UserSchema.statics.getUsersRegWeekly = function(idapp, nrec) { +UserSchema.statics.getUsersRegWeekly = function (idapp, nrec) { const query = [ { $match: { idapp, - date_reg: {$gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec))}, + date_reg: { $gte: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, }, { @@ -3583,26 +3632,26 @@ UserSchema.statics.getUsersRegWeekly = function(idapp, nrec) { timezone: 'Europe/Rome', }, }, - count: {$sum: 1}, + count: { $sum: 1 }, }, }, { - $sort: {_id: 1}, + $sort: { _id: 1 }, }, ]; return query; }; -UserSchema.statics.getnumRegNDays = function(idapp, nrec) { +UserSchema.statics.getnumRegNDays = function (idapp, nrec) { const query = [ { $match: { idapp, - date_reg: {$lt: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec))}, + date_reg: { $lt: tools.IncDateNow(-(1000 * 60 * 60 * 24 * nrec)) }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, }, { @@ -3614,17 +3663,17 @@ UserSchema.statics.getnumRegNDays = function(idapp, nrec) { timezone: 'Europe/Rome', }, }, - count: {$sum: 1}, + count: { $sum: 1 }, }, }, { - $sort: {_id: 1}, + $sort: { _id: 1 }, }, ]; return query; }; -UserSchema.statics.calcnumRegUntilDay = async function(idapp) { +UserSchema.statics.calcnumRegUntilDay = async function (idapp) { const User = this; return await User.aggregate(User.getnumRegNDays(idapp, 30)).then((arr) => { @@ -3633,7 +3682,7 @@ UserSchema.statics.calcnumRegUntilDay = async function(idapp) { }; -UserSchema.statics.calcRegDaily = async function(idapp) { +UserSchema.statics.calcRegDaily = async function (idapp) { const User = this; return await User.aggregate(User.getUsersRegDaily(idapp, 60)).then(ris => { @@ -3642,7 +3691,7 @@ UserSchema.statics.calcRegDaily = async function(idapp) { }); }; -UserSchema.statics.calcRegWeekly = async function(idapp) { +UserSchema.statics.calcRegWeekly = async function (idapp) { const User = this; return await User.aggregate(User.getUsersRegWeekly(idapp, 20 * 7)).then(ris => { @@ -3659,24 +3708,24 @@ if (tools.INITDB_FIRSTIME) { // UserSchema.index({ surname: 1 }); } -UserSchema.statics.getUsernameByIndex = async function(idapp, index) { +UserSchema.statics.getUsernameByIndex = async function (idapp, index) { const myrec = await User.findOne({ idapp, index, - }, {username: 1}); + }, { username: 1 }); return (!!myrec) ? myrec.username : ''; }; -UserSchema.statics.ricalcolaIndex = async function(idapp) { +UserSchema.statics.ricalcolaIndex = async function (idapp) { const User = this; const arrusers = await User.find({ idapp, - $or: [{deleted: {$exists: false}}, {deleted: {$exists: true, $eq: false}}], - }).sort({old_order: 1}); + $or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }], + }).sort({ old_order: 1 }); let index = 0; try { for (const user of arrusers) { @@ -3686,8 +3735,8 @@ UserSchema.statics.ricalcolaIndex = async function(idapp) { index++; - const ris = await User.findOneAndUpdate({_id: user._id}, {$set: field}, - {new: false}); + const ris = await User.findOneAndUpdate({ _id: user._id }, { $set: field }, + { new: false }); } } catch (e) { console.error(e.message); @@ -3695,7 +3744,7 @@ UserSchema.statics.ricalcolaIndex = async function(idapp) { }; -UserSchema.statics.getInfoUser = async function(idapp, username) { +UserSchema.statics.getInfoUser = async function (idapp, username) { return { username, is7req: await User.isUserQualified7(idapp, username), @@ -3704,8 +3753,8 @@ UserSchema.statics.getInfoUser = async function(idapp, username) { }; -UserSchema.statics.checkIfSbloccatiRequisiti = async function( - idapp, allData, id) { +UserSchema.statics.checkIfSbloccatiRequisiti = async function ( + idapp, allData, id) { const User = this; const telegrambot = require('../telegram/telegrambot'); @@ -3725,8 +3774,8 @@ UserSchema.statics.checkIfSbloccatiRequisiti = async function( if (!!allData.precDataUser) { if ((!allData.precDataUser.is9req && is9req) && - !await User.isUserAlreadyQualified_2Invitati(idapp, - allData.myuser.username)) { + !await User.isUserAlreadyQualified_2Invitati(idapp, + allData.myuser.username)) { await User.setUserQualified_2Invitati(idapp, allData.myuser.username); // ORA HAI I 9 REQUISITI ! @@ -3751,7 +3800,7 @@ UserSchema.statics.checkIfSbloccatiRequisiti = async function( }; -UserSchema.statics.mettiSognoePaypal = async function(idapp, modifica) { +UserSchema.statics.mettiSognoePaypal = async function (idapp, modifica) { const User = this; let num = 0; @@ -3759,10 +3808,10 @@ UserSchema.statics.mettiSognoePaypal = async function(idapp, modifica) { arrusers = await User.find({ 'idapp': idapp, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}, - {subaccount: {$exists: false}}, - {subaccount: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }, + { subaccount: { $exists: false } }, + { subaccount: { $exists: true, $eq: false } }], }); for (const rec of arrusers) { @@ -3800,14 +3849,14 @@ UserSchema.statics.mettiSognoePaypal = async function(idapp, modifica) { allData.myuser = await User.getUserById(idapp, rec.id); if (!!allData.myuser) allData.precDataUser = await User.getInfoUser(idapp, - allData.myuser.username); + allData.myuser.username); else allData.precDataUser = null; const risupd = await User.findByIdAndUpdate(rec._id, { 'profile.email_paypal': rec.profile.email_paypal, 'profile.my_dream': rec.profile.my_dream, - }, {new: false}); + }, { new: false }); if (risupd) { await User.checkIfSbloccatiRequisiti(idapp, allData, rec.id); @@ -3816,15 +3865,15 @@ UserSchema.statics.mettiSognoePaypal = async function(idapp, modifica) { } } - return {num}; + return { num }; }; -UserSchema.statics.convSubAccount = async function(idapp) { +UserSchema.statics.convSubAccount = async function (idapp) { const User = this; // Solo i Cancellati ! - arrusers = await User.find({'idapp': idapp, deleted: true}); + arrusers = await User.find({ 'idapp': idapp, deleted: true }); let num = 0; for (const rec of arrusers) { // Cerca il suo Principale! @@ -3832,22 +3881,22 @@ UserSchema.statics.convSubAccount = async function(idapp) { idapp, 'profile.teleg_id': rec.profile.teleg_id, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }); if (trovato) { num++; - await User.findByIdAndUpdate(rec._id, {subaccount: true}, {new: false}); + await User.findByIdAndUpdate(rec._id, { subaccount: true }, { new: false }); } } - return {num}; + return { num }; }; -UserSchema.statics.getLastRec = async function(idapp) { +UserSchema.statics.getLastRec = async function (idapp) { const User = this; - lastrec = await User.find({idapp}).sort({date_reg: -1}).limit(1).lean(); + lastrec = await User.find({ idapp }).sort({ date_reg: -1 }).limit(1).lean(); if (!!lastrec) { return lastrec[0]; } else { @@ -3855,39 +3904,39 @@ UserSchema.statics.getLastRec = async function(idapp) { } }; -UserSchema.statics.DbOp = async function(idapp, mydata) { +UserSchema.statics.DbOp = async function (idapp, mydata) { const User = this; try { if (mydata.dbop === 'changeCellInt') { - arrusers = await User.find({'idapp': idapp}); + arrusers = await User.find({ 'idapp': idapp }); let num = 0; for (const rec of arrusers) { // DISATTIVATO: ORA NON MI SERVE PIU if (false) { let mycell = tools.removespaces( - rec.profile.intcode_cell + rec.profile.cell); - await User.findOneAndUpdate({_id: rec._id}, - {$set: {'profile.cell': mycell}}); + rec.profile.intcode_cell + rec.profile.cell); + await User.findOneAndUpdate({ _id: rec._id }, + { $set: { 'profile.cell': mycell } }); num++; } } - return {num}; + return { num }; // return User.updateMany({ idapp }, { $set: { 'profile.cell': { $concat: ["$profile.intcode_cell", "$profile.cell"] } } }) } else if (mydata.dbop === 'changeEmailLowerCase') { - arrusers = await User.find({'idapp': idapp}); + arrusers = await User.find({ 'idapp': idapp }); let num = 0; for (const rec of arrusers) { let myemail = rec.email.toLowerCase(); if (myemail !== rec.email) { - await User.findOneAndUpdate({_id: rec._id}, - {$set: {'email': myemail}}); + await User.findOneAndUpdate({ _id: rec._id }, + { $set: { 'email': myemail } }); num++; } } - return {num}; + return { num }; /*} else if (mydata.dbop === 'creaLista') { @@ -3917,10 +3966,10 @@ UserSchema.statics.DbOp = async function(idapp, mydata) { }; -UserSchema.statics.getExtraInfoByUsername = async function(idapp, username) { +UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) { const User = this; - let myuser = await User.findOne({idapp, username}); + let myuser = await User.findOne({ idapp, username }); if (myuser) { myuserextra = await User.addExtraInfo(idapp, myuser); } @@ -3928,7 +3977,7 @@ UserSchema.statics.getExtraInfoByUsername = async function(idapp, username) { return myuser._doc.profile; }; -UserSchema.statics.addExtraInfo = async function(idapp, recUser) { +UserSchema.statics.addExtraInfo = async function (idapp, recUser) { try { @@ -3944,58 +3993,58 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) { const listSentMyRequestFriends = await User.find({ idapp, 'profile.req_friends': { - $elemMatch: {username: {$eq: recUser.username}}, + $elemMatch: { username: { $eq: recUser.username } }, }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], - }, {username: 1}).lean(); + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], + }, { username: 1 }).lean(); recUser._doc.profile.asked_friends = listSentMyRequestFriends - ? listSentMyRequestFriends - : []; + ? listSentMyRequestFriends + : []; const listSentMyRequestGroups = await MyGroup.find({ idapp, 'req_users': { - $elemMatch: {username: {$eq: recUser.username}}, + $elemMatch: { username: { $eq: recUser.username } }, }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, MyGroup.getWhatToShow_Unknown()).lean(); recUser._doc.profile.asked_groups = listSentMyRequestGroups - ? listSentMyRequestGroups - : []; + ? listSentMyRequestGroups + : []; const listRefusedGroups = await MyGroup.find({ idapp, 'refused_users': { - $elemMatch: {username: {$eq: recUser.username}}, + $elemMatch: { username: { $eq: recUser.username } }, }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }, MyGroup.getWhatToShow_Unknown()).lean(); recUser._doc.profile.refused_groups = listRefusedGroups - ? listRefusedGroups - : []; + ? listRefusedGroups + : []; const listManageGroups = await MyGroup.find({ idapp, 'admins': { - $elemMatch: {username: {$eq: recUser.username}}, + $elemMatch: { username: { $eq: recUser.username } }, }, $or: [ - {deleted: {$exists: false}}, - {deleted: {$exists: true, $eq: false}}], + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], }).lean(); recUser._doc.profile.manage_mygroups = listManageGroups - ? listManageGroups - : []; + ? listManageGroups + : []; // Circuit> @@ -4003,12 +4052,12 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) { const useraccounts = await Account.getUserAccounts(idapp, recUser.username); - recUser._doc.profile = {...recUser._doc.profile, ...circuitobj, useraccounts}; + recUser._doc.profile = { ...recUser._doc.profile, ...circuitobj, useraccounts }; recUser._doc.calcstat = await User.calculateStat(idapp, recUser.username); recUser._doc.profile.calc = await User.calcOtherByUser(idapp, recUser._id); - + return recUser._doc; @@ -4019,25 +4068,25 @@ UserSchema.statics.addExtraInfo = async function(idapp, recUser) { return recUser; }; -UserSchema.statics.calcOtherByUser = async function(idapp, userId) { +UserSchema.statics.calcOtherByUser = async function (idapp, userId) { - const {MySkill} = require('../models/myskill'); - const {MyGood} = require('../models/mygood'); - const {MyHosp} = require('../models/myhosp'); + const { MySkill } = require('../models/myskill'); + const { MyGood } = require('../models/mygood'); + const { MyHosp } = require('../models/myhosp'); let calc = {}; - let numgoods = await MyGood.countDocuments({idapp, userId}); - let numskills = await MySkill.countDocuments({idapp, userId}); - let numhosps = await MyHosp.countDocuments({idapp, userId}); - + let numgoods = await MyGood.countDocuments({ idapp, userId }); + let numskills = await MySkill.countDocuments({ idapp, userId }); + let numhosps = await MyHosp.countDocuments({ idapp, userId }); + calc.numGoodsAndServices = numgoods + numskills + numhosps; return calc; }; -UserSchema.statics.createNewSubRecord = async function(idapp, req) { +UserSchema.statics.createNewSubRecord = async function (idapp, req) { const User = this; // console.log("GENERA TOKEN : "); @@ -4045,9 +4094,9 @@ UserSchema.statics.createNewSubRecord = async function(idapp, req) { let fieldkey = req.body.data.field; let data = req.body.data.data; - const filtro = {_id: userId}; + const filtro = { _id: userId }; - let fieldsvalue = {...data}; + let fieldsvalue = { ...data }; fieldsvalue.date_created = new Date(); fieldsvalue.date_updated = new Date(); @@ -4057,7 +4106,7 @@ UserSchema.statics.createNewSubRecord = async function(idapp, req) { }; set.profile[fieldkey] = fieldsvalue; - const rec = await User.findOneAndUpdate(filtro, {$set: set}, {new: false}); + const rec = await User.findOneAndUpdate(filtro, { $set: set }, { new: false }); return rec; }; @@ -4076,6 +4125,6 @@ class Hero { } } -module.exports = {User, Hero}; +module.exports = { User, Hero }; diff --git a/src/server/router/site_router.js b/src/server/router/site_router.js index 600cdf5..7b44dc9 100755 --- a/src/server/router/site_router.js +++ b/src/server/router/site_router.js @@ -26,6 +26,7 @@ router.post('/load', async (req, res) => { let datastat = { num_reg: await User.getUsersRegistered(idapp), + num_reg_today: await User.getUsersRegisteredToday(idapp), online_today: await User.getUsersOnLineToday(idapp), // num_passeggeri: await 0, // num_imbarcati: 0, @@ -46,6 +47,7 @@ router.post('/load', async (req, res) => { // imbarcati_weekly: 0, reg_weekly: await User.calcRegWeekly(idapp), lastsreg: await User.getLastUsers(idapp), + lastsonline: await User.getLastOnlineUsers(idapp), checkuser: await User.checkUser(idapp, username), // navi_partite: await Nave.getNaviPartite(idapp), // navi_in_partenza: await Nave.getNaviInPartenza(idapp),