- Import emails from a list to a DB

- Create Template Emails
- Options Email
This commit is contained in:
Paolo Arena
2019-12-04 02:03:44 +01:00
parent f7fa0c4909
commit 6adeb32d46
19 changed files with 1061 additions and 211 deletions

View File

@@ -69,30 +69,32 @@ NewstosentSchema.statics.findNewsletter_To_Send = function (idapp) {
const Newstosent = this;
return Newstosent.findOne({
// datetoSent: { $gte: tools.IncDateNow(-1000 * 60 * 60) },
datetoSent: { $gte: tools.IncDateNow(-1000 * 60 * 60) },
activate: true,
starting_job: false,
finish_job: false,
idapp
}).then((rec) => {
return (rec) ? rec._doc : null;
});
})
.sort({ datetoSent: 1 })
.then((rec) => {
return (rec) ? rec._doc : null;
});
};
NewstosentSchema.statics.findNewsletterPending_To_Send = function (idapp) {
const Newstosent = this;
// Resend the Email after N hours no other email sent.
const numhours = 8;
return Newstosent.findOne({
datestartJob: { $lt: tools.IncDateNow(0) },
activate: true,
starting_job: true,
finish_job: false,
lastemailsent_Job: { $gte: tools.IncDateNow(-1000 * 60 * 60 * numhours) },
lastemailsent_Job: { $gte: tools.IncDateNow(-1000 * 60 * 60 * 8) },
idapp
}).then((rec) => {
// console.log('findNewsletterPending_To_Send', rec);
return (rec) ? rec._doc : null;
});
};
@@ -109,6 +111,30 @@ NewstosentSchema.statics.findAllIdApp = function (idapp) {
});
};
NewstosentSchema.statics.getlast = async function (idapp) {
const Newstosent = this;
try {
const mydoc = await Newstosent.find({ idapp }).sort({ datestartJob: -1 }).limit(1);
return mydoc[0]._doc;
} catch (e) {
return null
}
};
NewstosentSchema.statics.isActivated = async function (_id) {
const Newstosent = this;
try {
const mydoc = await Newstosent.findOne({ _id });
return (mydoc._doc.activate);
} catch (e) {
return false
}
};
const Newstosent = mongoose.model('Newstosent', NewstosentSchema);
module.exports = { Newstosent };