@tiledesk/tiledesk-server
Version:
The Tiledesk server module
67 lines (56 loc) • 1.39 kB
JavaScript
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var winston = require('../../config/winston');
const DEFAULT_EVENTS_TTL_SEC = 3600;
function ttlSecondsFromEnv(raw, fallbackSec) {
if (raw == null || String(raw).trim() === '') return fallbackSec;
const n = Number(raw);
return Number.isFinite(n) && n >= 0 ? n : fallbackSec;
}
const eventsTtlSeconds = ttlSecondsFromEnv(process.env.EVENTS_TTL_SECONDS, DEFAULT_EVENTS_TTL_SEC);
winston.info('Events TTL seconds: ' + eventsTtlSeconds);
var EventSchema = new Schema({
name: {
type: String,
required: true,
index: true
},
attributes: {
type: Object,
},
// TODO FALLO EMBED per performance
project_user: {
type: Schema.Types.ObjectId,
ref: 'project_user',
index: true,
required: false
},
id_project: {
type: String,
required: true,
index: true
},
status: {
type: String,
required: true,
default: "stardard",
index: true
},
// id_user: {
// type: String,
// required: true,
// index: true
// },
createdBy: {
type: String,
required: true,
index: true
},
},{
timestamps: true
}
);
EventSchema.index({ id_project: 1, name: 1, createdAt: -1 });
EventSchema.index({ createdAt: 1 }, { expireAfterSeconds: eventsTtlSeconds });
var event = mongoose.model('event', EventSchema);
module.exports = event;