- Sending Newsletter, others settings.
This commit is contained in:
@@ -8,6 +8,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const { Settings } = require('./settings');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
@@ -113,13 +115,13 @@ MyEventSchema.statics.findAllIdApp = function (idapp) {
|
||||
|
||||
};
|
||||
|
||||
MyEventSchema.statics.getLastEvents = function (idapp) {
|
||||
MyEventSchema.statics.getLastEvents = async function (idapp) {
|
||||
const Event = this;
|
||||
|
||||
const lastn = 3;
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_EV', 1);
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $match: { idapp, dateTimeStart: { $gte: tools.IncDateNow(- 1000 * 60 * 60 * 24) } } },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'operators',
|
||||
@@ -152,7 +154,11 @@ MyEventSchema.statics.getLastEvents = function (idapp) {
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
// console.table(arrrec);
|
||||
return arrrec.slice(-lastn)
|
||||
if (lastn > 0) {
|
||||
return arrrec.slice(0, lastn);
|
||||
} else {
|
||||
return arrrec
|
||||
}
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ SettingsSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
SettingsSchema.statics.getValDbSettings = function (idapp, key) {
|
||||
SettingsSchema.statics.getValDbSettings = function (idapp, key, def) {
|
||||
return Settings.findOne({ idapp, key })
|
||||
.then((myrec) => {
|
||||
// console.log('getValDbSettings', myrec, 'idapp', idapp);
|
||||
@@ -63,12 +63,12 @@ SettingsSchema.statics.getValDbSettings = function (idapp, key) {
|
||||
else
|
||||
return myrec.value_str;
|
||||
} else {
|
||||
return ''
|
||||
return def
|
||||
}
|
||||
|
||||
}).catch((err) => {
|
||||
console.error('getValDbSettings', err);
|
||||
return null;
|
||||
return def;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user