- aggiornato sistema per inviare le newsletter !

This commit is contained in:
Surya Paolo
2024-02-08 01:34:30 +01:00
parent 2151502d30
commit dacfc5a844
8 changed files with 223 additions and 85 deletions

View File

@@ -235,7 +235,7 @@ async function getDataNewsletter(lang, idapp) {
for (const user of arrml) {
data.totemail++;
if (user.statesub)
if (user.news_on)
data.totsubscribed++;
else
data.totunsubscribed++;
@@ -284,6 +284,38 @@ router.post('/setactivate', authenticate, async (req, res) => {
});
router.post('/unsubscribe_user', async (req, res) => {
hashemail = req.body.em;
email = req.body.email;
idapp = req.body.idapp;
locale = req.body.locale ?? 'it';
try {
const myuser = await User.findOne({ idapp, email }).lean();
if (myuser) {
const hashcalc = tools.getHash(myuser.email + myuser.username);
if (hashcalc === hashemail) {
await User.setNewsletter(idapp, myuser.username, false);
return res.send({
code: server_constants.RIS_UNSUBSCRIBED_OK,
msg: server_constants.RIS_SUBSCRIBED_MSG[locale]
});
}
}
} catch (e) {
console.error('err', e);
}
res.send({
code: server_constants.RIS_SUBSCRIBED_ERR
});
});
router.post('/unsubscribe', (req, res) => {
console.log('unsubscribe -> ', req.body);