- newsletter: prende la lista utenti (flag news_on)

- Abilita a Tutti la Newsletter news_on
- isCommerciale
- JobsInProgress
- PCB: Corretto Totali che era a zero
This commit is contained in:
Surya Paolo
2025-05-06 18:19:09 +02:00
parent 6e8d1fcff1
commit b77a0579f1
30 changed files with 4669 additions and 727 deletions

View File

@@ -177,6 +177,12 @@ const UserSchema = new mongoose.Schema({
news_on: {
type: Boolean,
},
diario_on: {
type: Boolean,
},
test: {
type: Boolean,
},
email_errata: {
type: Boolean,
},
@@ -640,7 +646,7 @@ UserSchema.statics.canHavePower = function (perm) {
try {
let consentito = false;
if (User.isAdmin(perm) || User.isManager(perm) ||
User.isEditor(perm) || User.isFacilitatore(perm)) {
User.isEditor(perm) || User.isCommerciale(perm) || User.isFacilitatore(perm)) {
consentito = true;
}
@@ -696,6 +702,14 @@ UserSchema.statics.isEditor = function (perm) {
return false;
}
};
UserSchema.statics.isCommerciale = function (perm) {
try {
return ((perm & shared_consts.Permissions.Commerciale) ===
shared_consts.Permissions.Commerciale);
} catch (e) {
return false;
}
};
UserSchema.statics.isGrafico = function (perm) {
try {
return ((perm & shared_consts.Permissions.Grafico) ===
@@ -759,7 +773,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
if (!token) {
console.warn('TOKEN VUOTO ! ');
return { user, code };
}
}
try {
@@ -822,7 +836,7 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
const end_find = process.hrtime.bigint();
// console.log(` User.findOne LEAN impiega ${Math.round(Number(end_find - start_find) / 1e6) / 1000} secondi.`);
}
if (user) {
const checkExpiry = tools.getEnableTokenExpiredByIdApp(user.idapp);
@@ -1350,6 +1364,16 @@ UserSchema.statics.setaportador_solidario = async function (
return !!myrec;
};
UserSchema.statics.setNewsletterToAll = async function (
idapp) {
const User = this;
return await User.updateMany({
idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
}, { $set: { 'news_on': true } },
{ new: false });
};
UserSchema.statics.setNewsletter = async function (
idapp, username, newsletter_on) {
const User = this;