- Create Newsletter Page: MailingList (without the class style, using Gulp tasks)#94
This commit is contained in:
114
src/server/models/newstosent.js
Normal file
114
src/server/models/newstosent.js
Normal file
@@ -0,0 +1,114 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const NewstosentSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
},
|
||||
activate: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
numemail_tot: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
numemail_sent: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
datetoSent: {
|
||||
type: Date
|
||||
},
|
||||
datestartJob: {
|
||||
type: Date
|
||||
},
|
||||
datefinishJob: {
|
||||
type: Date
|
||||
},
|
||||
lastemailsent_Job: {
|
||||
type: Date
|
||||
},
|
||||
starting_job: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
finish_job: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
error_job: {
|
||||
type: String,
|
||||
}
|
||||
});
|
||||
|
||||
NewstosentSchema.statics.getFieldsForSearch = function () {
|
||||
return ['name', 'surname', 'email']
|
||||
};
|
||||
|
||||
NewstosentSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
NewstosentSchema.statics.findNewsletter_To_Send = function (idapp) {
|
||||
const Newstosent = this;
|
||||
|
||||
return Newstosent.findOne({
|
||||
datetoSent: { $gte: tools.IncDateNow(-1000 * 60 * 60) },
|
||||
activate: true,
|
||||
starting_job: false,
|
||||
finish_job: false,
|
||||
idapp
|
||||
}).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) },
|
||||
idapp
|
||||
}).then((rec) => {
|
||||
return (rec) ? rec._doc : null;
|
||||
});
|
||||
};
|
||||
|
||||
NewstosentSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Newstosent = this;
|
||||
|
||||
const myfind = { idapp };
|
||||
|
||||
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
|
||||
|
||||
return Newstosent.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
});
|
||||
};
|
||||
|
||||
const Newstosent = mongoose.model('Newstosent', NewstosentSchema);
|
||||
|
||||
module.exports = { Newstosent };
|
||||
Reference in New Issue
Block a user