const mongoose = require('mongoose').set('debug', false) 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 CronSchema = new Schema({ idapp: { type: String, }, active: { type: Boolean, default: false, }, descr: { type: String, }, nomeFunzioneDbOp: { type: String, }, startTime: { // Orario iniziale (es. "08:30") type: String, default: "00:00" }, everyXHours: { // Esegui ogni X ore type: Number, default: 24 }, date_created: { type: Date, default: Date.now }, date_updated: { type: Date, }, }); CronSchema.statics.getFieldsForSearch = function () { return [{ field: 'descr', type: tools.FieldType.string }] }; CronSchema.statics.executeQueryTable = function (idapp, params, user) { params.fieldsearch = this.getFieldsForSearch(); return tools.executeQueryTable(this, idapp, params, user); }; CronSchema.statics.findAllIdApp = async function (idapp) { const Cron = this; try { return await Cron.find({ idapp }).then((arrrec) => { return arrrec; }); } catch (err) { console.error('Errore: ', err); } }; const Cron = mongoose.model('Cron', CronSchema); Cron.createIndexes() .then(() => { }) .catch((err) => { throw err; }); module.exports = { Cron };