- varie sistemazioni: filtri iscritti, profilo, ecc...
This commit is contained in:
@@ -745,7 +745,7 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
|
||||
// console.log('myrecread._id', myrecread._id.toString());
|
||||
|
||||
if (myrecread)
|
||||
risnotif = await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||
risnotif = await globalTables.sendNotifCmd(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -756,7 +756,7 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
|
||||
}
|
||||
|
||||
} else {
|
||||
risnotif = await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
|
||||
risnotif = await globalTables.sendNotifCmd(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2539,8 +2539,10 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
const msgOrig = i18n.__({ phrase, locale: user.lang }, usernameOrig);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
if (phrase !== 'HANDSHAKE_SET') {
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
|
||||
@@ -1398,6 +1398,17 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
ris = globalTables.replaceUsername(req.body.idapp, mydata.search_username, mydata.replace_username);
|
||||
}
|
||||
} else if (mydata.dbop === 'replaceAportadorSolidario') {
|
||||
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
ris = globalTables.replaceAportadorSolidario(req.body.idapp, mydata.search_username, mydata.replace_username);
|
||||
}
|
||||
} else if (mydata.dbop === 'SearchString') {
|
||||
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
mystr = await globalTables.SearchString(req.body.idapp, mydata.search);
|
||||
}
|
||||
ris = { mystr };
|
||||
|
||||
} else if (mydata.dbop === 'copyFrom1To14') {
|
||||
const idapporig = 1;
|
||||
|
||||
@@ -10,6 +10,8 @@ require('../models/subscribers');
|
||||
|
||||
const { ObjectId } = require('mongodb');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const { Booking } = require('../models/booking');
|
||||
@@ -57,6 +59,7 @@ const { SendMsg } = require('../models/sendmsg');
|
||||
const { Permission } = require('../models/permission');
|
||||
const { MsgTemplate } = require('../models/msg_template');
|
||||
const { Graduatoria } = require('../models/graduatoria');
|
||||
|
||||
const Product = require('../models/product');
|
||||
const ProductInfo = require('../models/productInfo');
|
||||
const Producer = require('../models/producer');
|
||||
@@ -267,7 +270,7 @@ module.exports = {
|
||||
return process.env.ENABLE_PUSHNOTIFICATION === '1';
|
||||
},
|
||||
|
||||
async sendNotif(typenotif, idnotif, res, idapp, user, recnotif, cmd) {
|
||||
async sendNotifCmd(typenotif, idnotif, res, idapp, user, recnotif, cmd) {
|
||||
// Controlla nelle impostazioni che tipo di Notifica visualizzare
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
@@ -518,24 +521,112 @@ module.exports = {
|
||||
return await this.SendMsgToParam(idapp, params);
|
||||
},
|
||||
|
||||
SearchString: async function (idapp, searchString) {
|
||||
const db = mongoose.connection.db;
|
||||
let result = '';
|
||||
let resultPrima = '';
|
||||
|
||||
if (!searchString)
|
||||
return '';
|
||||
|
||||
try {
|
||||
// Ottieni tutte le collezioni del database
|
||||
const collections = await db.listCollections().toArray();
|
||||
const collectionNames = collections.map(collection => collection.name);
|
||||
|
||||
for (const collectionName of collectionNames) {
|
||||
// Crea l'indice di testo per la collezione
|
||||
await db.collection(collectionName).createIndex({ "$**": "text" });
|
||||
|
||||
if (collectionName !== 'sendnotifs') {
|
||||
// Cerca nella collezione
|
||||
const found = await db.collection(collectionName).find({
|
||||
$and: [
|
||||
{ idapp: idapp },
|
||||
{ $text: { $search: searchString } },
|
||||
{ 'profile.username_telegram': { $exists: false } }
|
||||
]
|
||||
}).toArray();
|
||||
|
||||
|
||||
if (found.length > 0) {
|
||||
resultPrima += `Risultati trovati nella collezione: ${collectionName} (${found.length} record)\n`;
|
||||
|
||||
result += `Risultati trovati nella collezione: ${collectionName}\n`;
|
||||
for (const record of found) {
|
||||
result += JSON.stringify(record) + '\n';
|
||||
}
|
||||
result += '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result === '') {
|
||||
result = 'La stringa non è stata trovata in nessuna collezione.';
|
||||
}
|
||||
} catch (error) {
|
||||
result = `Errore durante la ricerca: ${error.message}`;
|
||||
} finally {
|
||||
|
||||
}
|
||||
|
||||
return resultPrima + '\n\n' + result;
|
||||
},
|
||||
|
||||
replaceAportadorSolidario: async function (idapp, search_username, replace_username) {
|
||||
|
||||
console.log('INIZIO replaceAportadorSolidario')
|
||||
|
||||
if (!search_username || !replace_username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ris = await User.updateMany({ idapp, aportador_iniziale: search_username },
|
||||
{
|
||||
$set:
|
||||
{ aportador_iniziale: replace_username }
|
||||
});
|
||||
console.log('aportador_iniziale result = ', ris);
|
||||
|
||||
ris = await User.updateMany({ idapp, aportador_solidario: search_username },
|
||||
{
|
||||
$set:
|
||||
{ aportador_solidario: replace_username }
|
||||
});
|
||||
console.log('aportador_solidario result = ', ris);
|
||||
|
||||
},
|
||||
replaceUsername: async function (idapp, search_username, replace_username) {
|
||||
|
||||
if (!search_username || !replace_username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const test = false;
|
||||
|
||||
|
||||
console.log('INIZIO replaceUsername')
|
||||
|
||||
try {
|
||||
let ris = null;
|
||||
console.log('replaceUsername = ', search_username, replace_username);
|
||||
|
||||
const dir = tools.getdirByIdApp(idapp, true);
|
||||
|
||||
tools.move(dir + server_constants.DIR_UPLOAD + '/profile/' + search_username, dir + server_constants.DIR_UPLOAD + '/profile/' + replace_username, function callback() {
|
||||
console.log(' ... moved dir', dir + server_constants.DIR_UPLOAD + '/profile/' + search_username, dir + server_constants.DIR_UPLOAD + '/profile/' + replace_username);
|
||||
});
|
||||
|
||||
if (test) {
|
||||
// esco...
|
||||
|
||||
} else {
|
||||
|
||||
ris = await User.findOneAndUpdate({ idapp, username: search_username }, { $set: { username: replace_username } });
|
||||
console.log('username result = ', ris);
|
||||
|
||||
tools.move(server_constants.DIR_UPLOAD + 'profile/' + search_username, server_constants.DIR_UPLOAD + 'profile/' + replace_username, function callback() {
|
||||
console.log(' ... moved dir', server_constants.DIR_UPLOAD + 'profile/' + search_username, server_constants.DIR_UPLOAD + 'profile/' + replace_username);
|
||||
});
|
||||
ris = await User.findOneAndUpdate({ idapp, username: search_username }, { $set: { username: replace_username } });
|
||||
console.log('username result = ', ris);
|
||||
|
||||
ris = await User.findOneAndUpdate({ idapp, 'profile.username_telegram': search_username }, { $set: { 'profile.username_telegram': replace_username } });
|
||||
console.log('profile.username_telegram result = ', ris);
|
||||
@@ -586,6 +677,46 @@ module.exports = {
|
||||
{ $set: { 'admins.$.username': replace_username } });
|
||||
console.log('Circuit.admins.username result = ', ris);
|
||||
|
||||
ris = await Circuit.updateMany({ idapp, 'createdBy': search_username },
|
||||
{ $set: { 'createdBy': replace_username } });
|
||||
console.log('Circuit.createdBy result = ', ris);
|
||||
|
||||
ris = await MyGroup.updateMany({ idapp, 'createdBy': search_username },
|
||||
{ $set: { 'createdBy': replace_username } });
|
||||
console.log('MyGroup.createdBy result = ', ris);
|
||||
|
||||
ris = await MyElem.updateMany(
|
||||
{
|
||||
idapp,
|
||||
$or: [
|
||||
{ 'containerHtml': { $regex: search_username, $options: 'i' } },
|
||||
{ 'link': { $regex: search_username, $options: 'i' } }
|
||||
]
|
||||
},
|
||||
[
|
||||
{
|
||||
$set: {
|
||||
containerHtml: {
|
||||
$replaceAll: {
|
||||
input: "$containerHtml",
|
||||
find: search_username,
|
||||
replacement: replace_username
|
||||
}
|
||||
},
|
||||
link: {
|
||||
$replaceAll: {
|
||||
input: "$link",
|
||||
find: search_username,
|
||||
replacement: replace_username
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
console.log('MyElem.containerHtml result = ', ris);
|
||||
|
||||
ris = await Circuit.updateMany({ idapp, 'req_users.username': search_username },
|
||||
{ $set: { 'req_users.$.username': replace_username } });
|
||||
console.log('Circuit.req_users.username result = ', ris);
|
||||
@@ -611,6 +742,41 @@ module.exports = {
|
||||
{ $set: { 'refused_users.$.username': replace_username } });
|
||||
console.log('MyGroup.refused_users.username result = ', ris);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
ris = await SendNotif.updateMany({ idapp, 'sender': search_username },
|
||||
{ $set: { 'sender': replace_username } });
|
||||
console.log('SendNotif.sender result = ', ris);
|
||||
|
||||
try {
|
||||
|
||||
ris = await SendNotif.updateMany({ idapp, 'dest': search_username },
|
||||
{ $set: { 'dest': replace_username } });
|
||||
console.log('SendNotif.dest result = ', ris);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
ris = await Reaction.updateMany({ idapp, 'username': search_username },
|
||||
{ $set: { 'username': replace_username } });
|
||||
console.log('Reaction.dest result = ', ris);
|
||||
|
||||
ris = await SendMsg.updateMany({ idapp, 'dest': search_username },
|
||||
{ $set: { 'dest': replace_username } });
|
||||
console.log('SendMsg.dest result = ', ris);
|
||||
|
||||
ris = await SendMsg.updateMany({ idapp, 'origin': search_username },
|
||||
{ $set: { 'origin': replace_username } });
|
||||
console.log('SendMsg.origin result = ', ris);
|
||||
|
||||
|
||||
ris = await Booking.updateMany({ idapp, 'username': search_username },
|
||||
{ $set: { 'username': replace_username } });
|
||||
console.log('Booking.username result = ', ris);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
@@ -46,6 +46,7 @@ module.exports = {
|
||||
FILTER_USER_WITHOUT_USERNAME_TELEGRAM: 8388608,
|
||||
FILTER_USER_PROVINCE: 16777216,
|
||||
FILTER_USER_SENZA_PROVINCE: 33554432,
|
||||
FILTER_USER_SENZA_CIRCUITO: 67108864,
|
||||
|
||||
OPTIONS_SEARCH_ONLY_FULL_WORDS: 1,
|
||||
OPTIONS_SEARCH_USER_ONLY_FULL_WORDS: 2,
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.1.15
|
||||
1.1.16
|
||||
Reference in New Issue
Block a user