ensl_gathers/db/models/archivedGather.js

32 lines
713 B
JavaScript
Raw Normal View History

2015-09-21 21:59:00 +00:00
"use strict";
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var archivedGatherSchema = new Schema({
createdAt: { type: Date, default: Date.now },
gather: { type: Schema.Types.Mixed, required: true }
});
archivedGatherSchema.index({ createdAt: -1 });
2015-09-22 18:48:57 +00:00
archivedGatherSchema.static({
recent: function (callback) {
this
.where({})
.sort({createdAt: -1})
.limit(5)
.exec(callback);
2015-09-26 11:16:39 +00:00
},
archive: function (gather, callback) {
2015-09-26 16:02:32 +00:00
// Do not try to fix this
// failed attempts to fix this: 1
let data = JSON.parse(JSON.stringify(gather.toJson()));
2015-09-26 11:16:39 +00:00
this.create({
2015-09-26 16:02:32 +00:00
gather: data
2015-09-26 11:16:39 +00:00
}, callback);
2015-09-22 18:48:57 +00:00
}
2015-09-21 21:59:00 +00:00
});
module.exports = mongoose.model("ArchivedGather", archivedGatherSchema);