- aggiornato sistema per inviare le newsletter !
This commit is contained in:
@@ -56,6 +56,9 @@ const UserSchema = new mongoose.Schema({
|
||||
message: '{VALUE} is not a valid email'
|
||||
}*/
|
||||
},
|
||||
hash: {
|
||||
type: String,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
@@ -164,6 +167,12 @@ const UserSchema = new mongoose.Schema({
|
||||
news_on: {
|
||||
type: Boolean,
|
||||
},
|
||||
email_errata: {
|
||||
type: Boolean,
|
||||
},
|
||||
lastid_newstosent: {
|
||||
type: String
|
||||
},
|
||||
aportador_solidario: { // da cancellare
|
||||
type: String,
|
||||
},
|
||||
@@ -1146,6 +1155,70 @@ UserSchema.statics.setaportador_solidario = async function (
|
||||
return !!myrec;
|
||||
};
|
||||
|
||||
UserSchema.statics.setNewsletter = async function (
|
||||
idapp, username, newsletter_on) {
|
||||
const User = this;
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
};
|
||||
|
||||
const myrec = await User.findOneAndUpdate(myquery,
|
||||
{ $set: { 'news_on': newsletter_on } }, { new: false });
|
||||
|
||||
return !!myrec;
|
||||
};
|
||||
|
||||
UserSchema.statics.setEmailErrata = async function (
|
||||
idapp, username, email_errata) {
|
||||
const User = this;
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
const myquery = {
|
||||
'idapp': idapp,
|
||||
'username': username,
|
||||
};
|
||||
|
||||
const myrec = await User.findOneAndUpdate(myquery,
|
||||
{ $set: { email_errata } }, { new: false });
|
||||
|
||||
return !!myrec;
|
||||
};
|
||||
|
||||
UserSchema.statics.isEmailErrata = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({
|
||||
idapp, username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).then((rec) => {
|
||||
return ((rec) ? rec.email_errata : false);
|
||||
}).catch((e) => {
|
||||
return false;
|
||||
});
|
||||
};
|
||||
UserSchema.statics.isNewsletterOn = async function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({
|
||||
idapp, username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).then((rec) => {
|
||||
return ((rec) ? rec.news_on : false);
|
||||
}).catch((e) => {
|
||||
console.error('isNewsletterOn', e);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
UserSchema.statics.setVerifiedByAportadorToALL = async function () {
|
||||
|
||||
return await User.updateMany({}, { $set: { 'verified_by_aportador': true } },
|
||||
@@ -1549,6 +1622,19 @@ UserSchema.statics.getUsernameById = async function (idapp, id) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUsernameByEmail = async function (idapp, email) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({
|
||||
idapp, email,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}, { username: 1 }).then((myuser) => {
|
||||
return ((myuser) ? myuser.username : '');
|
||||
}).catch((e) => {
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getUserById = function (idapp, id) {
|
||||
const User = this;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user