diff --git a/.vscode/launch.json b/.vscode/launch.json index 9acd2e2..36d3e5b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,13 +1,14 @@ { "version": "0.2.0", "configurations": [ + { "type": "node", "request": "launch", "name": "Launch via Nodemon", "program": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js", "restart": true, - "runtimeExecutable": "node", + "runtimeExecutable": "/usr/local/bin/node", "runtimeArgs": [ "--inspect=9229" // Use "--inspect=0.0.0.0:9229" for remote debugging ], @@ -30,7 +31,7 @@ "name": "Launch Trace Warning", "program": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js", "restart": true, - "runtimeExecutable": "node", + "runtimeExecutable": "/usr/local/bin/node", "runtimeArgs": [ "--trace-warnings" // Use "--inspect=0.0.0.0:9229" for remote debugging ], diff --git a/src/server/locales/en.json b/src/server/locales/en.json index 97d939e..cdee867 100755 --- a/src/server/locales/en.json +++ b/src/server/locales/en.json @@ -35,8 +35,8 @@ "CIRCUIT_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel circuito %s", "CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s", "CIRCUIT_REQUEST": "Richiesta di entrare nel Circuito %s da parte di %s", - "CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del circuito %s da parte di %s", - "CIRCUIT_ADDED_ADMIN_YOU": "Sei stato aggiunto come Amministratore del circuito %s da parte di %s", + "CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore/Amministratrice del circuito %s da parte di %s", + "CIRCUIT_ADDED_ADMIN_YOU": "Sei stato aggiunto come Amministratore/Amministratrice del circuito %s da parte di %s", "CIRCUIT_REMOVED_ADMIN": "E' stato rimosso l'incarico di Amministratore a %s del circuito %s da parte di %s", "CIRCUIT_REMOVED_ADMIN_YOU": "Ti è stato rimosso l'incarico di Amministratore del circuito %s da parte di %s", "RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il Circuito %s da parte di %s", diff --git a/src/server/locales/it.json b/src/server/locales/it.json index 92849cf..5455137 100644 --- a/src/server/locales/it.json +++ b/src/server/locales/it.json @@ -37,8 +37,8 @@ "GROUP_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel gruppo %s", "GROUP_CREATED": "✅ %s ha creato un nuovo Gruppo chiamato %s", "GROUP_REQUEST": "Richiesta di entrare nel Gruppo %s da parte di %s", - "GROUPS_ADDED_ADMIN_GROUP": "E' stato aggiunto %s come Amministratore del gruppo %s da parte di %s", - "GROUPS_ADDED_ADMIN_GROUP_YOU": "Sei stato aggiunto come Amministratore del gruppo %s da parte di %s", + "GROUPS_ADDED_ADMIN_GROUP": "E' stato aggiunto %s come Amministratore/Amministratrice del gruppo %s da parte di %s", + "GROUPS_ADDED_ADMIN_GROUP_YOU": "Sei stato aggiunto come Amministratore/Amministratrice del gruppo %s da parte di %s", "GROUPS_REMOVED_ADMIN_GROUP": "E' stato rimosso l'incarico di Amministratore a %s del gruppo %s da parte di %s", "GROUPS_REMOVED_ADMIN_GROUP_YOU": "Ti è stato rimosso l'incarico di Amministratore del gruppo %s da parte di %s", "RICHIESTA_BLOCCO_GRUPPO": "Richiesta di bloccare il Gruppo %s da parte di %s", @@ -58,9 +58,9 @@ "CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP": "il gruppo %s ha chiesto di entrare nel %s (con %s iscritti)", "CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s", "CIRCUIT_REQUEST": "Richiesta di entrare nel %s da parte di %s", - "CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del %s da parte di %s", - "CIRCUIT_ADDED_ADMIN_YOU": "%s sei stato aggiunto come Amministratore del %s da parte di %s", - "CIRCUIT_REMOVED_ADMIN": "E' stato rimosso l'incarico di Amministratore a %s del %s da parte di %s", + "CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore/Amministratrice del %s da parte di %s", + "CIRCUIT_ADDED_ADMIN_YOU": "%s sei stato aggiunto come Amministratore/Amministratrice del %s da parte di %s", + "CIRCUIT_REMOVED_ADMIN": "E' stato rimosso l'incarico di Amministratore/Amministratrice a %s del %s da parte di %s", "CIRCUIT_REMOVED_ADMIN_YOU": "%s ti è stato rimosso l'incarico di Amministratore del %s da parte di %s", "RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il %s da parte di %s", "CIRCUIT_ELIMINATO": "Il %s è stato eliminato da parte di %s", diff --git a/src/server/models/myelem.js b/src/server/models/myelem.js index aded41e..aae6b09 100755 --- a/src/server/models/myelem.js +++ b/src/server/models/myelem.js @@ -105,7 +105,10 @@ const MyElemSchema = new Schema({ type: Boolean, }, number: { - type: String, + type: Number, + }, + num2: { + type: Number, }, imgback: { type: String, diff --git a/src/server/models/stat.js b/src/server/models/stat.js index 5cbae64..49cc195 100755 --- a/src/server/models/stat.js +++ b/src/server/models/stat.js @@ -99,7 +99,7 @@ StatSchema.statics.calculateStats = async function (idapp) { diffusorilist: await User.getDiffusoriUsers(idapp), receiveRislist: await User.getReceiveRISUsers(idapp), receiveRislistgroup: await MyGroup.getReceiveRISGroups(idapp), - strettelist: await User.getBestStretteDiManoUsers(idapp), + strettelist: await User.getLastStretteDiManoUsers(idapp), num_transaz_tot: await Movement.getTotal_Transactions(idapp), tot_RIS_transati: await Movement.getTot_RIS_Transati(idapp), num_circuiti: await Circuit.getnumCircuits(idapp), @@ -113,7 +113,7 @@ StatSchema.statics.calculateStats = async function (idapp) { if (trova_se_oggi) { // Aggiorna il record di oggi: const ris = await Stat.findOneAndUpdate({ _id: trova_se_oggi._id }, { $set: datastat }, { new: true }); - console.log('ris', ris); + // console.log('ris', ris); } else { // Aggiungi un nuovo record: await Stat.insertMany([datastat]); @@ -154,6 +154,10 @@ StatSchema.statics.getStats = async function (idapp) { let datastat = null; + if (tools.testing()) { + isOld = true; + } + if (isOld) { datastat = await Stat.calculateStats(idapp); diff --git a/src/server/models/user.js b/src/server/models/user.js index cfa962e..4a7d94e 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -4542,28 +4542,94 @@ UserSchema.statics.getLastUsers = async function (idapp) { const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 20); - return await User.find( + const myquery = [ { - idapp, - $or: [ - { deleted: { $exists: false } }, - { deleted: { $exists: true, $eq: false } }], + $match: { + idapp, + $or: [ + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], + }, }, { - username: 1, - name: 1, - surname: 1, - lasttimeonline: 1, - verified_by_aportador: 1, - idMyGroup: 1, - 'profile.img': 1, - date_reg: 1, - index: 1, - 'profile.nationality': 1, - }).sort({ date_reg: -1 }).limit(lastn).lean().then((arr) => { - //return JSON.stringify(arr) - return arr; - }); + $lookup: { + from: "users", + let: { + username: "$aportador_solidario", + idapp, + }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { + $eq: [ + "$$username", + "$username", + ], + }, + { + $eq: [ + "$$idapp", + "$idapp", + ], + }, + ], + }, + }, + }, + ], + as: "user_aportador", + }, + }, + { + $unwind: "$user_aportador", + }, + { + $replaceRoot: { + newRoot: { + $mergeObjects: [ + "$user_aportador", + "$$ROOT", + ], + }, + }, + }, + { + $project: { + username: 1, + name: 1, + surname: 1, + lasttimeonline: 1, + aportador_solidario: 1, + idMyGroup: 1, + "profile.img": 1, + "profile.resid_province": 1, + date_reg: 1, + index: 1, + "profile.nationality": 1, + "user_aportador.username": 1, + "user_aportador.name": 1, + "user_aportador.lasttimeonline": 1, + "user_aportador.surname": 1, + "user_aportador.profile.resid_province": 1, + "user_aportador.profile.img": 1, + }, + }, + { + $sort: { date_reg: -1 }, + }, + { + $limit: lastn, + }, + + ]; + + return await User.aggregate(myquery).then((arr) => { + //return JSON.stringify(arr) + return arr; + }); }; @@ -4588,6 +4654,7 @@ UserSchema.statics.getLastOnlineUsers = async function (idapp) { verified_by_aportador: 1, idMyGroup: 1, 'profile.img': 1, + 'profile.resid_province': 1, index: 1, }).sort({ lasttimeonline: -1 }).limit(lastn).lean().then((arr) => { //return JSON.stringify(arr) @@ -4601,26 +4668,94 @@ UserSchema.statics.getLastSharedLink = async function (idapp) { const lastn = 10; - return await User.find( + const myquery = [ { - idapp, - $or: [ - { deleted: { $exists: false } }, - { deleted: { $exists: true, $eq: false } }], + $match: { + idapp, + $or: [ + { deleted: { $exists: false } }, + { deleted: { $exists: true, $eq: false } }], + }, }, { - username: 1, - name: 1, - surname: 1, - lasttimeonline: 1, - verified_by_aportador: 1, - idMyGroup: 1, - date_reg: 1, - 'profile.img': 1, - index: 1, - }).sort({ date_tokenreg: -1 }).limit(lastn).lean().then((arr) => { - return arr; - }); + $lookup: { + from: "users", + let: { + username: "$aportador_solidario", + idapp, + }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { + $eq: [ + "$$username", + "$username", + ], + }, + { + $eq: [ + "$$idapp", + "$idapp", + ], + }, + ], + }, + }, + }, + ], + as: "user_aportador", + }, + }, + { + $unwind: "$user_aportador", + }, + { + $replaceRoot: { + newRoot: { + $mergeObjects: [ + "$user_aportador", + "$$ROOT", + ], + }, + }, + }, + { + $project: { + username: 1, + name: 1, + surname: 1, + lasttimeonline: 1, + aportador_solidario: 1, + idMyGroup: 1, + "profile.img": 1, + "profile.resid_province": 1, + date_reg: 1, + index: 1, + "profile.nationality": 1, + "user_aportador.username": 1, + "user_aportador.name": 1, + "user_aportador.lasttimeonline": 1, + "user_aportador.surname": 1, + "user_aportador.profile.resid_province": 1, + "user_aportador.profile.img": 1, + }, + }, + { + $sort: { date_reg: -1 }, + }, + { + $limit: lastn, + }, + + ]; + + return await User.aggregate(myquery).then((arr) => { + //return JSON.stringify(arr) + return arr; + }); }; @@ -4648,6 +4783,20 @@ UserSchema.statics.getBestStretteDiManoUsers = async function (idapp) { }; +UserSchema.statics.getLastStretteDiManoUsers = async function (idapp) { + const User = this; + + const lastn = 10; + + const myquery = await User.getQueryLastUsersStretteDiMano(idapp); + + return await User.aggregate(myquery).then(ris => { + // console.table(ris); + return ris; + }); + +}; + UserSchema.statics.getReceiveRISUsers = async function (idapp) { const User = this; @@ -5005,6 +5154,113 @@ UserSchema.statics.getQueryUsersStretteDiMano = async function (idapp) { return query; }; +UserSchema.statics.getQueryLastUsersStretteDiMano = async function (idapp) { + + const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 20); + + const query = [ + { + $match: { + idapp, + 'profile.handshake': { $exists: true }, + $or: [ + { + deleted: { + $exists: false, + }, + }, + { + deleted: { + $exists: true, + $eq: false, + }, + }, + ], + }, + }, + { $unwind: "$profile.handshake" }, + + // Ordiniamo in base alla data della handshake in modo decrescente + { $sort: { "profile.handshake.date": -1 } }, + + { + $lookup: { + from: "users", + let: { + username: "$profile.handshake.username", + idapp: idapp, + }, + pipeline: [ + { + $match: { + $expr: { + $and: [ + { + $eq: [ + "$$username", + "$username", + ], + }, + { + $eq: [ + "$$idapp", + "$idapp", + ], + }, + ], + }, + }, + }, + ], + as: "userfriend", + }, + }, + { $unwind: "$userfriend" }, + + // Raggruppiamo nuovamente gli utenti dopo l'ordinamento + { + $group: { + _id: "$_id", + userId: { $first: "$userId" }, + idapp: { $first: "$idapp" }, + username: { $first: "$username" }, + aportador_solidario: { $first: "$aportador_solidario" }, + name: { $first: "$name" }, + surname: { $first: "$surname" }, + lasttimeonline: { $first: "$lasttimeonline" }, + date_reg: { $first: "$date_reg" }, + userfriend: { + $first: { + profile: { + img: "$userfriend.profile.img", + resid_province: "$userfriend.profile.resid_province", + }, + username: "$userfriend.username", + name: "$userfriend.name", + surname: "$userfriend.surname", + } + }, + + profile: { + $first: { + img: "$profile.img", + handshake: "$profile.handshake", + resid_province: "$profile.resid_province", + }, + }, + handshakeDate: { $first: "$profile.handshake.date" }, + } + }, + { + $sort: { + handshakeDate: -1, + }, + }, + { $limit: lastn }, + ]; + return query; +}; + UserSchema.statics.getQueryReceiveRISUsers = function (idapp, hours) { const query = [