- 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
|
||||
}
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user