- Create Newsletter Page: MailingList (without the class style, using Gulp tasks)#94
This commit is contained in:
152
src/server/models/myevent.js
Normal file
152
src/server/models/myevent.js
Normal file
@@ -0,0 +1,152 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const MyEventSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
typol: {
|
||||
type: String,
|
||||
},
|
||||
short_tit: {
|
||||
type: String,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
},
|
||||
details: {
|
||||
type: String,
|
||||
},
|
||||
bodytext: {
|
||||
type: String,
|
||||
},
|
||||
dateTimeStart: {
|
||||
type: Date,
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
},
|
||||
bgcolor: {
|
||||
type: String,
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
img_small: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
wherecode: {
|
||||
type: String,
|
||||
},
|
||||
contribtype: {
|
||||
type: String,
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
},
|
||||
infoafterprice: {
|
||||
type: String,
|
||||
},
|
||||
teacher: {
|
||||
type: String,
|
||||
},
|
||||
teacher2: {
|
||||
type: String,
|
||||
},
|
||||
infoextra: {
|
||||
type: String,
|
||||
},
|
||||
linkpage: {
|
||||
type: String,
|
||||
},
|
||||
linkpdf: {
|
||||
type: String,
|
||||
},
|
||||
nobookable: {
|
||||
type: Boolean,
|
||||
},
|
||||
news: {
|
||||
type: Boolean,
|
||||
},
|
||||
canceled: {
|
||||
type: Boolean,
|
||||
},
|
||||
deleted: {
|
||||
type: Boolean,
|
||||
},
|
||||
dupId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
},
|
||||
modified: {
|
||||
type: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
MyEventSchema.statics.findAllIdApp = function (idapp) {
|
||||
const Event = this;
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { dateTimeStart: 1 } }
|
||||
];
|
||||
|
||||
return Event
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
return arrrec
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
MyEventSchema.statics.getLastEvents = function (idapp) {
|
||||
const Event = this;
|
||||
|
||||
const lastn = 3;
|
||||
|
||||
const query = [
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { dateTimeStart: 1 } }
|
||||
];
|
||||
|
||||
return Event
|
||||
.aggregate(query)
|
||||
.then((arrrec) => {
|
||||
return arrrec.slice(-lastn)
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
|
||||
MyEventSchema.statics.getFieldsForSearch = function () {
|
||||
return ['short_tit', 'title', 'teacher', 'details']
|
||||
};
|
||||
|
||||
MyEventSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
// console.log(' createIndex MyEvent Index...');
|
||||
// MyEventSchema.index({ short_tit: 'text', title: 'text', teacher: 'text', details: 'text' });
|
||||
}
|
||||
|
||||
|
||||
const MyEvent = mongoose.model('MyEvent', MyEventSchema);
|
||||
|
||||
module.exports = { MyEvent };
|
||||
Reference in New Issue
Block a user