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

View File

@@ -227,6 +227,8 @@ module.exports = {
const sendemail = require('../sendemail');
const { User } = require('../models/user');
/// ... rivedere il crea gruppo... notifiche...
try {
if (!recnotif.typesend) {
@@ -248,7 +250,8 @@ module.exports = {
usernameDest: recnotif.usernameDest ? recnotif.usernameDest : recnotif.dest,
tag: recnotif.tag ? recnotif.tag : '',
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) {
@@ -287,6 +290,8 @@ module.exports = {
try {
console.log('SendMsgToParam', params.typesend);
const { User } = require('../models/user');
let textsent = '';
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;
},
};