- fix notifiche

This commit is contained in:
Surya Paolo
2024-05-10 00:58:38 +02:00
parent 3b1b2b9c83
commit 1d5002ea0f
6 changed files with 26 additions and 28 deletions

View File

@@ -161,7 +161,7 @@ sendNotifSchema.statics.getRecNotif = function (id) {
};
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord, typedir) {
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord, qualinotif) {
const SendNotif = this;
if (!lastdataread)
@@ -173,8 +173,13 @@ sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, l
{ datenotif: { $gt: new Date(lastdataread) } }
];
if (typedir) {
arrfilter.push({typedir});
if (qualinotif) {
if (qualinotif === shared_consts.QualiNotifs.CIRCUITS) {
arrfilter.push({ typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS });
} else {
arrfilter.push({ typedir: { $ne: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS } });
}
}
return SendNotif.find({

View File

@@ -3281,8 +3281,8 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
}
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
outres.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
outres.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
} else {
outres.cansend = false;

View File

@@ -84,8 +84,8 @@ router.post('/load', authenticate, async (req, res) => {
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, false, '', data.path);
}
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
const arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
const arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
/// E' QUIIII !!!!
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);

View File

@@ -34,7 +34,7 @@ router.get('/setall/:username/:qualinotif/:idapp', authenticate, async (req, res
const idapp = req.params.idapp;
const username = req.params.username;
const qualinotif = req.params.qualinotif;
const qualinotif = parseInt(req.params.qualinotif);
const username_call = req.user.username;
try {
@@ -115,7 +115,7 @@ router.get('/delall/:username/:qualinotif/:idapp', authenticate, async (req, res
const idapp = req.params.idapp;
const username = req.params.username;
const qualinotif = req.params.qualinotif;
const qualinotif = parseInt(req.params.qualinotif);
const username_call = req.user.username;
try {
@@ -143,18 +143,13 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
return getNotif(req, res);
});
router.get('/:username/:lastdataread/:idapp/:qualinotif', authenticate, (req, res) => {
return getNotif(req, res);
});
function getNotif(req, res) {
async function getNotif(req, res) {
try {
// tools.mylog('GET NotifS : ', req.params);
const username = req.params.username;
const lastdataread = req.params.lastdataread;
const idapp = req.params.idapp;
const qualinotif = req.params.qualinotif;
// var category = req.params.category;
@@ -163,21 +158,18 @@ function getNotif(req, res) {
return res.status(404).send({ code: server_constants.RIS_CODE_NOT_MY_USERNAME });
}
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, qualinotif).then(async (arrnotif) => {
// const wait = new Promise((resolve, reject) => {
// setTimeout(() => {
const arrnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
const arrnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
//++Todo: Ottimizzare ! Non occorre inviare tutti questi dati !!! Solo per il Circuito ?!
const userprofile = await User.getExtraInfoByUsername(idapp, req.user.username);
return res.send({ arrnotif, userprofile });
return res.send({ arrnotif, arrnotifcoins, userprofile });
}).catch((e) => {
console.log(e.message);
res.status(400).send(e);
});
} catch (e) {
console.log(e.message);
res.status(400).send(e);
}
};

View File

@@ -902,8 +902,8 @@ router.post('/updatesaldo', authenticate, async (req, res) => {
userprofile
}
ris.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_OTHERS);
ris.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.TypeNotifs.TYPEDIR_CIRCUITS);
ris.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER, shared_consts.QualiNotifs.OTHERS);
ris.arrrecnotifcoins = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIFCOINS_FOR_USER, shared_consts.QualiNotifs.CIRCUITS);
return res.send({ ris });

View File

@@ -3,7 +3,8 @@ module.exports = {
CHECK_READ_GUIDELINES: 1,
CHECK_SEE_VIDEO_PRINCIPI: 2,
},
LIMIT_NOTIF_FOR_USER: 200,
LIMIT_NOTIF_FOR_USER: 100,
LIMIT_NOTIFCOINS_FOR_USER: 200,
QUERYTYPE_MYGROUP: 1,
QUERYTYPE_REFUSED_USER_GRP: 2,