diff --git a/src/server/models/circuit.js b/src/server/models/circuit.js index 4b79f81..b6cdbb2 100755 --- a/src/server/models/circuit.js +++ b/src/server/models/circuit.js @@ -504,6 +504,86 @@ CircuitSchema.statics.getUserCircuits = async function(idapp, username) { }; +CircuitSchema.statics.getUsersSingleCircuit = async function(idapp, username, circuitname, circuitId) { + + const {User} = require('../models/user'); + + try { + let aggr1 = [ + { + $match: { + idapp: idapp, + 'profile.mycircuits': { + $elemMatch: {circuitname: {$eq: circuitname}}, + }, + }, + }, + + /*{ + $lookup: { + from: 'circuits', + as: 'circuit', + let: {circuitname: circuitname, idapp: '$idapp'}, + pipeline: [ + { + $match: + { + $expr: + { + $and: + [ + {$eq: ['$name', '$$circuitname']}, + {$eq: ['$idapp', '$$idapp']}, + + ], + }, + }, + }, + ], + }, + + }, + {$unwind: '$circuit'}, + */ + { + $project: {username: 1, profile: 1, idapp: 1 /*, 'circuit.name': 1, 'circuit._id': 1*/}, + + }, + { + $lookup: { + from: 'accounts', + as: 'account', + let: {username: '$username', idapp: '$idapp', circuitId: circuitId /*, circuitId: '$circuit._id' */ }, + pipeline: [ + { + $match: + { + $expr: + { + $and: + [ + {$eq: ['$$username', '$username']}, + {$eq: ['$$idapp', '$idapp']}, + {$eq: ['$$circuitId', '$circuitId']}, + ], + }, + }, + }, + ], + }, + }, + {$unwind: '$account'}, + ]; + + ris = await User.aggregate(aggr1); + + return ris; + } catch (e) { + console.error('e', e); + } + +}; + CircuitSchema.statics.getCircolanteSingolaTransaz = function(accountorigTable, accountdestTable) { let circolante = 0; @@ -647,7 +727,7 @@ CircuitSchema.statics.updateData = async function(idapp, circuitname) { }; const risult = await this.updateOne({idapp, name: circuitname}, {$set: paramstoupdate}); - console.log('risult', risult) + console.log('risult', risult); } catch (e) { console.error('Err', e); diff --git a/src/server/models/user.js b/src/server/models/user.js index dfdee6f..dc913ad 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -1238,15 +1238,21 @@ UserSchema.statics.createNewReqRegistrationGetLink = async function(idapp, usern }); if (user) { - if (!user.date_tokenreg || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) { + if (!user.date_tokenreg || (!user.tokenreg) || (user.tokenreg && (user.date_tokenreg < new Date().getTime()))) { // Se รจ scaduto, ne crea uno nuovo // Creo il tokenforgot user.tokenreg = jwt.sign(user._id.toHexString(), process.env.SIGNCODE). toString(); - user.tokenreg = user.tokenreg.replaceAll('.', ''); - user.tokenreg = user.tokenreg.replaceAll('/', ''); - user.tokenreg = user.tokenreg.substring(1,8); + if (user.tokenreg){ + try { + user.tokenreg = user.tokenreg.replaceAll('.', ''); + user.tokenreg = user.tokenreg.replaceAll('/', ''); + user.tokenreg = user.tokenreg.substring(1,8); + }catch (e) { + console.error('err', e); + } + } user.date_tokenreg = tools.AddDate(new Date(), 2); diff --git a/src/server/router/circuits_router.js b/src/server/router/circuits_router.js index d50cfc6..0ece4e4 100755 --- a/src/server/router/circuits_router.js +++ b/src/server/router/circuits_router.js @@ -31,7 +31,6 @@ async function getCircuitRecAdminsInfo(idapp, data) { router.post('/load', authenticate, async (req, res) => { const idapp = req.body.idapp; const path = req.body.path; - const circuitId = req.body.circuitId; const usernameOrig = req.user.username; try { @@ -48,7 +47,7 @@ router.post('/load', authenticate, async (req, res) => { const whatshowUsers = await User.getWhatToShow_IfFriends(idapp, req.user.username); - let users_in_circuit = []; + /*let users_in_circuit = []; if (data) { users_in_circuit = await User.find( @@ -61,6 +60,9 @@ router.post('/load', authenticate, async (req, res) => { whatshowUsers, ).lean(); } + */ + + const users_in_circuit = await Circuit.getUsersSingleCircuit(idapp, req.user.username, data.name, data._id); data = await getCircuitRecAdminsInfo(idapp, data); diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 14da898..2373993 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -426,6 +426,10 @@ router.post('/settable', authenticate, async (req, res) => { await SendNotif.createNewNotification(req, res, {groupnameDest, circuitnameDest}, params.table, myrec, typedir, typeid); } + if (params.table === 'circuits') { + await Circuit.updateData(myrec.idapp, myrec.name); + } + if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) { // nuovo Record: // aggiungi il creatore al gruppo stesso @@ -789,6 +793,7 @@ router.patch('/chval', authenticate, async (req, res) => { } } + if (mydata.table === 'users') { if (camporequisiti) { await User.checkIfSbloccatiRequisiti(idapp, allData, id); diff --git a/src/server/server.js b/src/server/server.js index 8ec88a6..a5948eb 100755 --- a/src/server/server.js +++ b/src/server/server.js @@ -436,6 +436,9 @@ async function inizia() { await telegrambot.sendMsgTelegramToTheAdminAllSites(`Ciao Admin\n` + `๐Ÿ”…๐Ÿ”…๐Ÿ”… Il Server col BOT di {appname} รจ appena ripartito!`, false); } + + console.log(process.versions); + } catch (e) { } diff --git a/src/server/tools/general.js b/src/server/tools/general.js index e24f929..b1ee26d 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -1867,6 +1867,11 @@ module.exports = { } } + if (params.filterextra) { + if (params.filterextra.length > 0) + query = [...params.filterextra]; + } + if (filtriadded) { if (filtriadded.length > 0) query.push({$match: {$and: filtriadded}}); diff --git a/src/server/tools/prova.js b/src/server/tools/prova.js new file mode 100644 index 0000000..57ae9ea --- /dev/null +++ b/src/server/tools/prova.js @@ -0,0 +1,177 @@ +[ + { + "0": { + "$match": { + "idapp": "13", + "profile.mycircuits": { + "$elemMatch": { + "circuitname": { + "$eq": "RISO Test" + } + } + } + } + }, + "1": { + "$lookup": { + "from": "circuits", + "as": "circuit", + "let": { + "circuitname": "RISO Test", + "idapp": "$idapp" + }, + "pipeline": [ + { + "$match": { + "$expr": { + "$and": [ + { + "$eq": [ + "$name", + "$$circuitname" + ] + }, + { + "$eq": [ + "$idapp", + "$$idapp" + ] + } + ] + } + } + } + ] + } + }, + "2": { + "$unwind": "$circuit" + }, + "3": { + "$project": { + "username": 1, + "profile": 1, + "idapp": 1, + "circuit.name": 1, + "circuit._id": 1 + } + }, + "4": { + "$lookup": { + "from": "accounts", + "as": "account", + "let": { + "username": "$username", + "idapp": "$idapp", + "circuitId": "$circuit._id" + }, + "pipeline": [ + { + "$match": { + "$expr": { + "$and": [ + { + "$eq": [ + "$$username", + "$username" + ] + }, + { + "$eq": [ + "$$idapp", + "$idapp" + ] + }, + { + "$eq": [ + "$$circuitId", + "$circuitId" + ] + } + ] + } + } + } + ] + } + }, + "5": { + "$unwind": "$account" + } + }, + { + "$match": { + "idapp": "13" + } + }, + { + "$sort": { + "desc": 1 + } + }, + { + "$addFields": { + "myId1": { + "$toObjectId": "$userId" + } + } + }, + { + "$lookup": { + "from": "users", + "localField": "myId1", + "foreignField": "_id", + "as": "user" + } + }, + { + "$replaceRoot": { + "newRoot": { + "$mergeObjects": [ + { + "$arrayElemAt": [ + "$user", + 0 + ] + }, + "$$ROOT" + ] + } + } + }, + { + "$project": { + "username": 1, + "profile.img": 1, + "profile.mycircuits": 1, + "profile.qualifica": 1, + "account.saldo": 1, + "reported": 1, + "date_report": 1, + "username_who_report": 1 + } + }, + { + "$group": { + "_id": null, + "count": { + "$sum": 1 + }, + "results": { + "$push": "$$ROOT" + } + } + }, + { + "$project": { + "count": 1, + "rows": { + "$slice": [ + "$results", + 0, + 10 + ] + } + } + } +]