- 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

@@ -51,7 +51,7 @@ const DisciplineSchema = new Schema({
type: Boolean,
},
teachers: [{
type: String,
type: String,
}],
});
@@ -71,6 +71,22 @@ DisciplineSchema.statics.findAllIdApp = function (idapp) {
};
DisciplineSchema.statics.getDisciplineforNewsletter = function (idapp) {
const Discipline = this;
const query = [
{ $match: { $and: [{ idapp }, { showinnewsletter: true }] } },
{ $sort: { order: 1 } }
];
return Discipline
.aggregate(query)
.then((arrrec) => {
return arrrec
})
};
DisciplineSchema.statics.getFieldsForSearch = function () {
return ['label', 'description']

View File

@@ -20,6 +20,9 @@ const MailingListSchema = new Schema({
type: String,
trim: true,
},
hash: {
type: String,
},
name: {
type: String,
trim: true,
@@ -28,6 +31,10 @@ const MailingListSchema = new Schema({
type: String,
trim: true,
},
statesub: {
type: Boolean,
default: true
},
lastid_newstosent: {
type: String
}
@@ -42,10 +49,10 @@ MailingListSchema.statics.executeQueryTable = function (idapp, params) {
return tools.executeQueryTable(this, idapp, params);
};
MailingListSchema.statics.findAllIdApp = function (idapp) {
MailingListSchema.statics.findAllIdAppSubscribed = function (idapp) {
const MailingList = this;
const myfind = { idapp };
const myfind = { idapp, statesub: true };
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
@@ -54,6 +61,38 @@ MailingListSchema.statics.findAllIdApp = function (idapp) {
});
};
MailingListSchema.statics.findAllIdApp = async function (idapp) {
const MailingList = this;
const myfind = { idapp };
return await MailingList.find(myfind, (err, arrrec) => {
return arrrec
});
};
MailingListSchema.statics.isUnsubscribed = async function (idapp, hash) {
const MailingList = this;
let myperson = await MailingList.findOne({ idapp, hash });
console.log('myperson', myperson);
if (!!myperson) {
return (!myperson.statesub)
}
};
MailingListSchema.statics.findByHash = function (idapp, hash) {
const MailingList = this;
const myfind = { idapp, hash };
// Extract only the Teacher where in the users table the field permissions is set 'Teacher' bit.
return MailingList.findOne(myfind, (err, rec) => {
return rec
});
};
const MailingList = mongoose.model('MailingList', MailingListSchema);
module.exports = { MailingList };

View File

@@ -120,12 +120,38 @@ MyEventSchema.statics.getLastEvents = function (idapp) {
const query = [
{ $match: { idapp } },
{
$lookup: {
from: 'operators',
localField: 'teacher',
foreignField: 'username',
as: 'op1'
}
},
{
$lookup: {
from: 'operators',
localField: 'teacher2',
foreignField: 'username',
as: 'op2'
}
},
{ "$addFields": { "contribtype": { "$toObjectId": "$contribtype" } } },
{
$lookup: {
from: 'contribtypes',
localField: 'contribtype',
foreignField: '_id',
as: 'contrib'
}
},
{ $sort: { dateTimeStart: 1 } }
];
return Event
.aggregate(query)
.then((arrrec) => {
// console.table(arrrec);
return arrrec.slice(-lastn)
})

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 };

View File

@@ -0,0 +1,47 @@
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 OpzEmailSchema = new Schema({
key: {
type: String,
default: ''
},
label_it: {
type: String,
}
});
OpzEmailSchema.statics.getFieldsForSearch = function () {
return ['label_it']
};
OpzEmailSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, 0, params);
};
OpzEmailSchema.statics.findAllIdApp = async function (idapp) {
const OpzEmail = this;
return await OpzEmail.find({}, (err, arrrec) => {
return arrrec
});
};
const OpzEmail = mongoose.model('OpzEmail', OpzEmailSchema);
module.exports = { OpzEmail };

View File

@@ -30,6 +30,13 @@ const SettingsSchema = new Schema({
},
value_num: {
type: Number,
},
value_bool: {
type: Boolean,
},
serv: {
type: Boolean,
default: false
}
});
@@ -45,12 +52,14 @@ SettingsSchema.statics.executeQueryTable = function (idapp, params) {
SettingsSchema.statics.getValDbSettings = function (idapp, key) {
return Settings.findOne({ idapp, key })
.then((myrec) => {
console.log('getValDbSettings', myrec, 'idapp', idapp);
// console.log('getValDbSettings', myrec, 'idapp', idapp);
if (myrec) {
if (myrec.type === tools.FieldType.date)
return myrec.value_date;
if (myrec.type === tools.FieldType.number)
else if (myrec.type === tools.FieldType.number)
return myrec.value_num;
else if (myrec.type === tools.FieldType.boolean)
return myrec.value_bool;
else
return myrec.value_str;
} else {
@@ -64,10 +73,10 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key) {
};
SettingsSchema.statics.findAllIdApp = function (idapp) {
SettingsSchema.statics.findAllIdApp = function (idapp, serv) {
const Settings = this;
const myfind = { idapp };
const myfind = { idapp, serv };
return Settings.find(myfind, (err, arrrec) => {
return arrrec

View File

@@ -0,0 +1,66 @@
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 TemplEmailSchema = new Schema({
idapp: {
type: String,
},
subject: {
type: String,
},
testoheadermail: {
type: String,
},
content: {
type: String,
},
img: {
type: String,
},
content2: {
type: String,
},
img2: {
type: String,
},
options: [{
type: String,
}]
});
TemplEmailSchema.statics.getFieldsForSearch = function () {
return ['']
};
TemplEmailSchema.statics.executeQueryTable = function (idapp, params) {
params.fieldsearch = this.getFieldsForSearch();
return tools.executeQueryTable(this, idapp, params);
};
TemplEmailSchema.statics.findAllIdApp = async function (idapp) {
const TemplEmail = this;
const myfind = { idapp };
return await TemplEmail.find(myfind, (err, arrrec) => {
return arrrec
});
};
const TemplEmail = mongoose.model('TemplEmail', TemplEmailSchema);
module.exports = { TemplEmail };