correzione numseen, numfav, ...: ora li ho aggiunti alle tabelle...

This commit is contained in:
Surya Paolo
2023-10-01 01:24:47 +02:00
parent 142dcadca9
commit b6579832b6
27 changed files with 8952 additions and 8875 deletions

View File

@@ -99,6 +99,9 @@ const sendNotifSchema = new Schema({
textaddTelegram: {
type: String,
},
textcontent_Telegram: {
type: String,
},
linkaddTelegram: {
type: String,
}
@@ -145,7 +148,7 @@ sendNotifSchema.statics.getRecNotif = function (id) {
};
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp) {
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord) {
const SendNotif = this;
if (!lastdataread)
@@ -157,7 +160,7 @@ sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, l
{ 'dest': username },
{ 'datenotif': { $gt: new Date(lastdataread) } },
],
}).lean().sort({ datenotif: -1 }).then(async (arrnotif) => {
}).lean().limit(limitrecord).sort({ datenotif: -1 }).then(async (arrnotif) => {
// console.log('arrnotif', arrnotif.length);
return this.compileOtherFields(arrnotif);
@@ -172,6 +175,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
const numchars = 80;
let newdescr = '';
let newdescrtelegram = '';
let mydescr = '';
let myidrec = '';
let sender = recnotif.sender ? recnotif.sender : '';
@@ -205,7 +209,9 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
tag = 'newevent';
if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_NEW_REC) {
newdescr = i18n.__('NEW_EVENT', userorig, mydescr);
let eventobj = await tools.getEventForTelegram(recnotif.myrectableorig, mydescr, userorig);
newdescr = eventobj.newdescr;
newdescrtelegram = eventobj.newdescrtelegram;
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_SEND_MSG) {
newdescr = i18n.__('EVENT_SEND_MSG', userorig, recnotif.title, recnotif.msg);
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_ATTEND) {
@@ -217,11 +223,12 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
else
newdescr = i18n.__('SET_ATTEND', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.descr);
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
tag = 'attend';
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
recnotif.linkaddTelegram = 'Vedi post';
}
recnotif.textcontent_Telegram = newdescrtelegram;
recnotif.linkaddTelegram = i18n.__('SHOW_POST');
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
recnotif.openUrl = '/my/' + sender;
@@ -539,7 +546,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
tag = 'favorite';
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
recnotif.linkaddTelegram = 'Vedi post';
recnotif.linkaddTelegram = i18n.__('SHOW_POST');
}
recnotif.tag = recnotif.tag ? recnotif.tag : tag;
@@ -898,9 +905,11 @@ sendNotifSchema.statics.createNewNotification = async function (req, res, params
myrecnotif.idrec = rec._id;
}
myrecnotif.typedir = typedir;
myrecnotif.typeid = typeid;
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
return true;
@@ -972,24 +981,27 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
if (myrectableorig) {
for (const city of myrectableorig.idCity) {
const prov = await City.getProvinceByIdCity(city);
arrprovinces.push(await City.getProvinceByIdCity(city));
arrregions.push(await City.getRegionByIdCity(city));
arrcircuits.push(await City.getCircuitNameBystrProv(prov));
if (myrecnotifpass.idrec && myrecnotifpass.idrec !== '0') {
// const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
const myrectableorig = await mytable.getCompleteRecord(myrecnotifpass.idapp, myrecnotifpass.idrec);
if (myrectableorig) {
for (const city of myrectableorig.idCity) {
const prov = await City.getProvinceByIdCity(city);
arrprovinces.push(await City.getProvinceByIdCity(city));
arrregions.push(await City.getRegionByIdCity(city));
arrcircuits.push(await City.getCircuitNameBystrProv(prov));
}
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
idSector = myrectableorig.idSectorGood;
} else {
idSector = myrectableorig.idSector;
}
}
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
idSector = myrectableorig.idSectorGood;
} else {
idSector = myrectableorig.idSector;
}
myrecnotifpass.myrectableorig = myrectableorig;
}
myrecnotifpass.myrectableorig = myrectableorig;
}
}