fix: ordinamento membri (namecomplete (concat: name, surname, username)

This commit is contained in:
Surya Paolo
2023-04-12 15:37:54 +02:00
parent 5bb6611384
commit f13786fca1
10 changed files with 500 additions and 86 deletions

203
mongodb/Members.mongodb Normal file
View File

@@ -0,0 +1,203 @@
use('test_FreePlanet');
let aggregation = [
{
$match: {
idapp: "13",
"profile.mycircuits": {
$elemMatch: {
circuitname: {
$eq: "Circuito RIS Bologna",
},
},
},
},
},
{
$lookup: {
from: "circuits",
as: "circuit",
let: {
circuitname: "Circuito RIS Bologna",
idapp: "$idapp",
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
"$name",
"$$circuitname",
],
},
{
$eq: [
"$idapp",
"$$idapp",
],
},
],
},
},
},
],
},
},
{
$unwind: "$circuit",
},
{
$project: {
username: 1,
name: 1,
surname: 1,
date_reg: 1,
profile: 1,
idapp: 1,
"circuit.name": 1,
"circuit._id": 1,
},
},
{
$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",
],
},
],
},
},
},
],
},
},
{
$unwind: "$account",
},
{
$match: {
idapp: "13",
},
},
{
$addFields: {
myId1: {
$toObjectId: "$userId",
},
namecomplete: {
$concat: [
{
$toLower: "$name",
},
{
$toLower: "$surname",
},
{ $toLower: "$username" },
],
},
},
},
{
$lookup: {
from: "users",
localField: "myId1",
foreignField: "_id",
as: "user",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$user",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
username: 1,
name: 1,
surname: 1,
"profile.img": 1,
"profile.mycircuits": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
"account._id": 1,
"account.saldo": 1,
"account.fidoConcesso": 1,
"account.qta_maxConcessa": 1,
"account.totTransato": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
namecomplete: 1,
date_reg: 1,
},
},
{
$sort: {
date_reg: 1,
},
},
{
$group: {
_id: null,
count: {
$sum: 1,
},
results: {
$push: "$$ROOT",
},
},
},
{
$project: {
count: 1,
rows: {
$slice: [
"$results",
1,
15,
],
},
},
},
];
db.users.aggregate(aggregation);

View File

@@ -0,0 +1,23 @@
use('test_FreePlanet');
let aggregation = [
{
$match: {
idapp: "13",
"profile.favorite": {
$elemMatch:
{ id: '10256', tab: 4 }
}
},
},
{
$group:
{
_id: null,
count: { $sum: 1 },
}
},
{ $project: { _id: 0 } }
];
db.users.aggregate(aggregation);

View File

@@ -86,5 +86,6 @@
"SALDO_VARIATO": "[Circuito %s] l'utente %s ha variato il Saldo di %s da %s a %s %s", "SALDO_VARIATO": "[Circuito %s] l'utente %s ha variato il Saldo di %s da %s a %s %s",
"FIDOCONCESSO_VARIATO": "[Circuito %s] l'utente %s ha variato il Fido Concesso di %s da %s a %s %s", "FIDOCONCESSO_VARIATO": "[Circuito %s] l'utente %s ha variato il Fido Concesso di %s da %s a %s %s",
"QTAMAX_VARIATO": "[Circuito %s] l'utente %s ha variato la quantità massima concessa di %s da %s a %s %s", "QTAMAX_VARIATO": "[Circuito %s] l'utente %s ha variato la quantità massima concessa di %s da %s a %s %s",
"CLICCA_QUI": "CLICCA QUI" "SET_FAVORITE": "%s ha messo 'Mi Piace' al tuo post: %s",
"SET_FAVORITE_OTHERS": "%s e altre %s persone hanno messo 'Mi Piace' al tuo post: %s"
} }

View File

@@ -96,6 +96,9 @@ const sendNotifSchema = new Schema({
options: { options: {
type: Array, type: Array,
}, },
textaddTelegram: {
type: String,
}
}); });
sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) { sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) {
@@ -180,11 +183,11 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) { if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) {
if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) { if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) {
newdescr = i18n.__('<strong>%s</strong> new Good: %s', userorig, mydescr); newdescr = i18n.__('<strong>%s</strong> new Good: %s', userorig, mydescr);
recnotif.openUrl = '/mygood/' + myidrec; recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYGOODS, true) + myidrec;
tag = 'newgood'; tag = 'newgood';
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) { } else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
newdescr = i18n.__('<strong>%s</strong> new Service: %s', userorig, mydescr); newdescr = i18n.__('<strong>%s</strong> new Service: %s', userorig, mydescr);
recnotif.openUrl = '/myservice/' + myidrec; recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYSKILLS, true) + myidrec;
tag = 'newservice'; tag = 'newservice';
} }
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) { } else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
@@ -222,7 +225,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
} }
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) { } else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
tag = 'group'; tag = 'group';
recnotif.openUrl = '/grp/' + recnotif.paramsObj.groupnameDest; recnotif.openUrl = shared_consts.getDirectoryByTable('mygroups', true) + recnotif.paramsObj.groupnameDest;
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) { if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
newdescr = i18n.__('GROUP_CREATED', sender, recnotif.paramsObj.groupnameDest); newdescr = i18n.__('GROUP_CREATED', sender, recnotif.paramsObj.groupnameDest);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) { } else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
@@ -280,7 +283,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
} }
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) { } else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
tag = 'circuit'; tag = 'circuit';
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path;
strtipocontoOrig = recnotif.paramsObj.extrarec.contoComOrig ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO'); strtipocontoOrig = recnotif.paramsObj.extrarec.contoComOrig ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
strtipocontoDest = recnotif.paramsObj.extrarec.contoComDest ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO'); strtipocontoDest = recnotif.paramsObj.extrarec.contoComDest ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
let groupOComorig = recnotif.paramsObj.extrarec.contoComOrig ? recnotif.paramsObj.extrarec.contoComOrig : recnotif.paramsObj.extrarec.grouporig; let groupOComorig = recnotif.paramsObj.extrarec.contoComOrig ? recnotif.paramsObj.extrarec.contoComOrig : recnotif.paramsObj.extrarec.grouporig;
@@ -393,7 +396,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
} }
tag = 'sendcoin'; tag = 'sendcoin';
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ? recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path; //++Todo: dove lo mando ?
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT) { } else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT) {
if (myorig) { if (myorig) {
@@ -411,7 +414,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
} }
tag = 'sendcoin'; tag = 'sendcoin';
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ? recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path; //++Todo: dove lo mando ?
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) { } else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', qty, symbol, newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', qty, symbol,
username_action) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol); username_action) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol);
@@ -456,6 +459,19 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED_TO_ME', qty, symbol, destinatario); newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED_TO_ME', qty, symbol, destinatario);
tag = 'sendcoin'; tag = 'sendcoin';
} }
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
// ++ Controlla se esiste già
let esitegia = recnotif.paramsObj.recObjCreator.exist; // ++
if (esitegia)
newdescr = i18n.__('SET_FAVORITE_OTHERS', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.numfav - 1, recnotif.paramsObj.recObjCreator.descr);
else
newdescr = i18n.__('SET_FAVORITE', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.descr);
tag = 'favorite';
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
recnotif.textaddTelegram = 'Vedi post';
} }
recnotif.tag = recnotif.tag ? recnotif.tag : tag; recnotif.tag = recnotif.tag ? recnotif.tag : tag;
@@ -645,6 +661,8 @@ sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlys
newstatus = shared_consts.CircuitsNotif.STATUS_COINS_REFUSED_SENT; newstatus = shared_consts.CircuitsNotif.STATUS_COINS_REFUSED_SENT;
} }
} else if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
// typeidsearch = shared_consts.TypeNotifs.ID_FAVORITE_ADDED;
} }
if (newstatus) { if (newstatus) {
@@ -877,6 +895,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
const mytable = globalTables.getTableByTableName(myrecnotifpass.tablerec); const mytable = globalTables.getTableByTableName(myrecnotifpass.tablerec);
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA || myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) || if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) { shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
@@ -896,6 +915,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
} }
myrecnotifpass.myrectableorig = myrectableorig; myrecnotifpass.myrectableorig = myrectableorig;
} }
}
myrecnotifpass = await this.getDescrAndLinkByRecNotif(myrecnotifpass, req.user.username); myrecnotifpass = await this.getDescrAndLinkByRecNotif(myrecnotifpass, req.user.username);
delete myrecnotifpass._doc['_id']; delete myrecnotifpass._doc['_id'];
@@ -907,6 +927,14 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
let send = false; let send = false;
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
if (shared_consts.TABLES_FAVORITE_BOOKMARK.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED)) {
send = true;
}
}
} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA || myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) || if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) { shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
// Estrai la Città, la Provincia e la regione. // Estrai la Città, la Provincia e la regione.
@@ -933,12 +961,13 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
} }
} }
} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) { if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) { if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
send = true; send = true;
} }
} }
}
if (send) { if (send) {
let myrecnotif = new SendNotif(myrecnotifpass); let myrecnotif = new SendNotif(myrecnotifpass);
@@ -999,6 +1028,9 @@ sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, usern
}; };
sendNotifSchema.statics.checkIfAlreadyExist = async function (idapp, tag, idpost, numtab) {
};
const SendNotif = mongoose.model('SendNotif', sendNotifSchema); const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
module.exports = { SendNotif: SendNotif }; module.exports = { SendNotif: SendNotif };

View File

@@ -13,6 +13,8 @@ const { Graduatoria } = require('../models/graduatoria');
// const {NavePersistente} = require('../models/navepersistente'); // const {NavePersistente} = require('../models/navepersistente');
// const { ExtraList } = require('../models/extralist'); // const { ExtraList } = require('../models/extralist');
const { MyGroup } = require('../models/mygroup'); const { MyGroup } = require('../models/mygroup');
const { Circuit } = require('../models/circuit'); const { Circuit } = require('../models/circuit');
@@ -464,6 +466,7 @@ const UserSchema = new mongoose.Schema({
tab: { type: Number }, tab: { type: Number },
}, },
], ],
version: { type: Number },
}, },
}); });
@@ -1911,9 +1914,24 @@ UserSchema.statics.removeFavorite = async function (
// Aggiungo il Favorite // Aggiungo il Favorite
UserSchema.statics.addFavorite = async function ( UserSchema.statics.addFavorite = async function (
idapp, username, id, tab) { req, idapp, username, id, tab) {
return await User.updateOne({ idapp, username }, const ris = await User.updateOne({ idapp, username },
{ $push: { 'profile.favorite': { id, tab } } }); { $push: { 'profile.favorite': { id, tab } } });
const { SendNotif } = require('../models/sendnotif');
const globalTables = require('../tools/globalTables');
// Invia una Notifica al Destinatario
const recObjCreator = await globalTables.getUserCreatorByNumTabAndId(idapp, id, tab);
if (recObjCreator) {
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: recObjCreator.username, recObjCreator, username_action: req.user.username }, false, shared_consts.TypeNotifs.TYPEDIR_FAVORITE,
shared_consts.TypeNotifs.ID_FAVORITE_ADDED);
}
return ris;
}; };
// Rimuovo il Bookmark // Rimuovo il Bookmark
UserSchema.statics.removeBookmark = async function ( UserSchema.statics.removeBookmark = async function (
@@ -3946,6 +3964,7 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
const { MyGood } = require('../models/mygood'); const { MyGood } = require('../models/mygood');
const { MyBacheca } = require('../models/mybacheca'); const { MyBacheca } = require('../models/mybacheca');
const { MyGroup } = require('../models/mygroup'); const { MyGroup } = require('../models/mygroup');
const globalTables = require('../tools/globalTables');
const numUsersReg = await User.countDocuments( const numUsersReg = await User.countDocuments(
{ {
@@ -3957,8 +3976,6 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
let numByTab = {}; let numByTab = {};
const globalTables = require('../tools/globalTables');
for (let table of shared_consts.TABLES_VISU_STAT_IN_HOME) { for (let table of shared_consts.TABLES_VISU_STAT_IN_HOME) {
let mytable = globalTables.getTableByTableName(table); let mytable = globalTables.getTableByTableName(table);
if (mytable) { if (mytable) {
@@ -4675,7 +4692,7 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
return myuser.profile; return myuser.profile;
}; };
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) { UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
try { try {
@@ -4764,6 +4781,22 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id); recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
if (version) {
let versattualeuser = 0;
if (!recUser.profile.version) {
recUser.version = 0;
versattualeuser = 0;
} else {
versattualeuser = recUser.profile.version;
}
if (versattualeuser < version) {
// Aggiornamento versione
recUser = await User.updateVersion(versattualeuser, recUser);
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.version' : version }});
}
}
return recUser; return recUser;
@@ -4774,6 +4807,17 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
return recUser; return recUser;
}; };
UserSchema.statics.updateVersion = async function (userversion, recUser) {
if (userversion < 063) {
recUser.profile.notifs.push( { dir: 11, value: 1 })
await User.findOneAndUpdate({_id: recUser._id}, {$set: { 'profile.notifs': recUser.profile.notifs }});
}
return recUser;
};
UserSchema.statics.calcOtherByUser = async function (idapp, userId) { UserSchema.statics.calcOtherByUser = async function (idapp, userId) {
const { MySkill } = require('../models/myskill'); const { MySkill } = require('../models/myskill');

View File

@@ -1346,6 +1346,9 @@ function load(req, res, version) {
const permissions = Permission.findAllIdApp(); const permissions = Permission.findAllIdApp();
// const versionstr = User....
// let version = tools.getVersionint(versionstr);
let newstosent = Promise.resolve([]); let newstosent = Promise.resolve([]);
let mailinglist = Promise.resolve([]); let mailinglist = Promise.resolve([]);
let mypage; let mypage;
@@ -1406,7 +1409,7 @@ function load(req, res, version) {
let myuserextra = null; let myuserextra = null;
if (req.user) { if (req.user) {
// askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username); // askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username);
myuserextra = User.addExtraInfo(idapp, req.user._doc, req.user); myuserextra = User.addExtraInfo(idapp, req.user._doc, req.user, version);
} }
return Promise.all([ return Promise.all([

View File

@@ -1557,7 +1557,7 @@ router.post('/cmd', authenticate, async (req, res) => {
if (cmd === shared_consts.CMD_USER.SET_FAVORITE) { if (cmd === shared_consts.CMD_USER.SET_FAVORITE) {
if (tab) { if (tab) {
if (value) if (value)
ris = await User.addFavorite(idapp, username, id, tab); ris = await User.addFavorite(req, idapp, username, id, tab);
else else
ris = await User.removeFavorite(idapp, username, id, tab); ris = await User.removeFavorite(idapp, username, id, tab);
} }

View File

@@ -132,6 +132,7 @@ const textlang = {
'CREATO_NUOVO_GRUPPO': '✅ Hai appena creato un nuovo Gruppo chiamato %s', 'CREATO_NUOVO_GRUPPO': '✅ Hai appena creato un nuovo Gruppo chiamato %s',
'ACCETTATO_NOTIFICA_ADMINS': '✅ l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)', 'ACCETTATO_NOTIFICA_ADMINS': '✅ l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
'GROUP_REQUEST': 'Richiesta di entrare nel Gruppo %s da parte di %s', 'GROUP_REQUEST': 'Richiesta di entrare nel Gruppo %s da parte di %s',
"CLICCA_QUI": "CLICCA QUI",
}, },
si: {}, si: {},
es: { es: {
@@ -883,7 +884,7 @@ module.exports = {
}; };
}, },
sendNotificationByUsername: async function (idapp, username, cmd, telegram, usernameOrig) { sendNotificationByUsername: async function (idapp, username, cmd, telegram, usernameOrig, recObjCreator) {
var { User } = require('../models/user'); var { User } = require('../models/user');
const { SendNotif } = require('../models/sendnotif'); const { SendNotif } = require('../models/sendnotif');
@@ -919,22 +920,7 @@ module.exports = {
} }
} else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) { } else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) {
descr = printf(this.get__('RICHIESTA_HANDSHAKE', lang), usernameOrig); // const foundIfAlready = await User.isMyHandShake(idapp, username, usernameOrig);
openUrl = '/my/' + usernameOrig;
tag = 'reqhandshake';
const userrecDest = await User.getUserShortDataByUsername(idapp, usernameOrig);
const foundIfAlreadyHandShake = await User.isMyHandShake(idapp, username, usernameOrig);
if (userrecDest) {
sendmynotif = false; // non lo rimandare 2 volte !
if (!foundIfAlreadyHandShake) {
// SEND TELEGRAM NOTIFICATION
telegrambot.askConfirmationUserFriend(idapp, shared_consts.CallFunz.RICHIESTA_HANDSHAKE, userrecDest, username, usernameOrig);
}
}
} }
} }
@@ -1770,6 +1756,11 @@ module.exports = {
return myrec ? myrec.id : -1 return myrec ? myrec.id : -1
}, },
getTableByNumTab(numtab) {
const myrec = shared_consts.MYTABS.find((rec) => rec.id === numtab)
return myrec ? myrec.table : ''
},
getGroupnameLookupPipeLine(params, proj) { getGroupnameLookupPipeLine(params, proj) {
let myquery = [ let myquery = [
@@ -1811,6 +1802,17 @@ module.exports = {
if (params.af_objId_tab) { if (params.af_objId_tab) {
const myobj = {}; const myobj = {};
myobj['myId' + num] = { '$toObjectId': '$' + params.lk_LF }; myobj['myId' + num] = { '$toObjectId': '$' + params.lk_LF };
if (params.lk_tab === 'users') {
myobj.namecomplete = {
$concat: [
{ $toLower: "$name" },
{ $toLower: "$surname" },
{ $toLower: "$username" },
],
};
}
query.push( query.push(
{ '$addFields': myobj }, { '$addFields': myobj },
); );
@@ -2202,14 +2204,6 @@ module.exports = {
// console.log('QUERYMATCH', query[0].$match.or); // console.log('QUERYMATCH', query[0].$match.or);
// console.log('filter', params.filter); // console.log('filter', params.filter);
if (params.sortBy) {
// maybe we want to sort by blog title or something
const mysort = { $sort: params.sortBy };
// console.log('sortBy', params.sortBy);
// console.table(mysort);
query.push(mysort);
}
let numrowend = params.endRow - params.startRow; let numrowend = params.endRow - params.startRow;
if (numrowend < 0) if (numrowend < 0)
numrowend = 1; numrowend = 1;
@@ -2611,6 +2605,14 @@ module.exports = {
if (q1) query = [...query, ...q1]; if (q1) query = [...query, ...q1];
} }
if (params.sortBy) {
// maybe we want to sort by blog title or something
const mysort = { $sort: params.sortBy };
// console.log('sortBy', params.sortBy);
// console.table(mysort);
query.push(mysort);
}
query.push( query.push(
{ {
$group: { $group: {
@@ -3854,6 +3856,11 @@ module.exports = {
let myhost = this.getHostByIdApp(params.idapp); let myhost = this.getHostByIdApp(params.idapp);
if (params.textaddTelegram) {
if (params.openUrl)
content = content + '\n' + '<a href="' + myhost + params.openUrl + '">' + params.textaddTelegram + '</a>';
}
/*if (params.openUrl) /*if (params.openUrl)
content = content + '\n' + '<a href="' + myhost + params.openUrl + '">' + i18n.__('OPEN PAGE') + '</a>'; content = content + '\n' + '<a href="' + myhost + params.openUrl + '">' + i18n.__('OPEN PAGE') + '</a>';

View File

@@ -227,6 +227,8 @@ module.exports = {
const sendemail = require('../sendemail'); const sendemail = require('../sendemail');
const { User } = require('../models/user');
/// ... rivedere il crea gruppo... notifiche... /// ... rivedere il crea gruppo... notifiche...
try { try {
if (!recnotif.typesend) { if (!recnotif.typesend) {
@@ -248,7 +250,8 @@ module.exports = {
usernameDest: recnotif.usernameDest ? recnotif.usernameDest : recnotif.dest, usernameDest: recnotif.usernameDest ? recnotif.usernameDest : recnotif.dest,
tag: recnotif.tag ? recnotif.tag : '', tag: recnotif.tag ? recnotif.tag : '',
actions: recnotif.actions ? recnotif.actions : [], actions: recnotif.actions ? recnotif.actions : [],
id: recnotif._id id: recnotif._id,
textaddTelegram: recnotif.textaddTelegram ? recnotif.textaddTelegram : '',
}; };
if (tools.isBitActive(recnotif.typesend, shared_consts.MessageOptions.Notify_ByPushNotification) && this.checkifSendPushNotification) { if (tools.isBitActive(recnotif.typesend, shared_consts.MessageOptions.Notify_ByPushNotification) && this.checkifSendPushNotification) {
@@ -287,6 +290,8 @@ module.exports = {
try { try {
console.log('SendMsgToParam', params.typesend); console.log('SendMsgToParam', params.typesend);
const { User } = require('../models/user');
let textsent = ''; let textsent = '';
const telegrambot = require('../telegram/telegrambot'); const telegrambot = require('../telegram/telegrambot');
@@ -536,5 +541,66 @@ module.exports = {
}, },
getNumFavoriteByIdObj: async function (idapp, numtab, id) {
const { User } = require('../models/user');
let query = [
{
$match: {
idapp,
"profile.favorite": {
$elemMatch:
{ id, tab: numtab }
}
},
},
{
$group:
{
_id: null,
count: { $sum: 1 },
}
},
{ $project: { _id: 0 } }
];
try {
const [result] = await User.aggregate(query);
return result ? result.count : 0;
} catch (err) {
return 0;
}
return 0;
},
getUserCreatorByNumTabAndId: async function (idapp, id, numtab) {
try {
const table = tools.getTableByNumTab(numtab);
const mytable = this.getTableByTableName(table);
const { User } = require('../models/user');
if (mytable) {
const rec = await mytable.findOne({ _id: id, idapp }, { username: 1, lang: 1, userId: 1, descr: 1 });
if (rec) {
const recuser = await User.getUserById(idapp, rec.userId);
let numfav = await this.getNumFavoriteByIdObj(idapp, numtab, id);
let exist = numfav > 1;
if (recuser)
return { userId: rec.userId, username: recuser.username, descr: rec.descr, id: rec._id, table, exist, numfav };
}
}
} catch (e) {
console.error('Err:', e);
}
return null;
},
}; };

View File

@@ -95,6 +95,10 @@ module.exports = {
SENDCOINS_REFUSE_SENT: 2222, SENDCOINS_REFUSE_SENT: 2222,
}, },
USERCMD: {
FAVORITE: 3001,
},
REPORT_FILT_RESP: 1, REPORT_FILT_RESP: 1,
REPORT_FILT_ATTIVITA: 2, REPORT_FILT_ATTIVITA: 2,
@@ -449,6 +453,9 @@ module.exports = {
TYPEDIR_HANDSHAKE: 10, TYPEDIR_HANDSHAKE: 10,
ID_HANDSHAKE_ACCEPTED: 2, ID_HANDSHAKE_ACCEPTED: 2,
TYPEDIR_FAVORITE: 11,
ID_FAVORITE_ADDED: 1,
TYPEDIR_TEST: 444, TYPEDIR_TEST: 444,
ID_TEST_NEW_REC: 1, ID_TEST_NEW_REC: 1,
}, },
@@ -523,7 +530,11 @@ module.exports = {
{ {
'dir': 5, 'dir': 5,
'value': 1 'value': 1
} },
{
'dir': 11,
'value': 1
},
], ],
CIRCUIT_STATUS: { CIRCUIT_STATUS: {
@@ -569,6 +580,8 @@ module.exports = {
reported: 1, reported: 1,
date_report: 1, date_report: 1,
username_who_report: 1, username_who_report: 1,
namecomplete: 1,
date_reg: 1,
}; };
if (proj_add) if (proj_add)
@@ -577,4 +590,26 @@ module.exports = {
return proj; return proj;
}, },
getDirectoryByTable(table, barre = false) {
let add = '';
if (barre)
add = '/';
if (table === 'myskills') {
return add + 'myservice' + add
} else if (table === 'mybachecas') {
return add + 'mypage' + add
} else if (table === 'myhosps') {
return add + 'myhosps' + add
} else if (table === 'mygoods') {
return add + 'mygood' + add
} else if (table === 'mygroups') {
return add + 'grp' + add
} else if (table === 'circuits') {
return add + 'circuit' + add
}
return ''
},
}; };