- Sending Newsletter, others settings.

This commit is contained in:
Paolo Arena
2019-12-04 18:20:50 +01:00
parent d2dc16b7fb
commit b92655c2e5
5 changed files with 33 additions and 15 deletions

View File

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