2015-08-05 00:41:43 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var mongoose = require("mongoose");
|
|
|
|
var Schema = mongoose.Schema;
|
|
|
|
|
|
|
|
var messageSchema = new Schema({
|
|
|
|
author: {
|
|
|
|
username: { type: String, required: true },
|
|
|
|
avatar: String
|
|
|
|
},
|
|
|
|
content: { type: String, required: true },
|
|
|
|
createdAt: { type: Date, default: Date.now, required: true }
|
|
|
|
});
|
|
|
|
|
2015-08-07 00:06:40 +00:00
|
|
|
messageSchema.index({ createdAt: 1 });
|
|
|
|
|
|
|
|
// Class Methods
|
|
|
|
|
|
|
|
messageSchema.statics.list = function (options, callback) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instance Methods
|
2015-08-05 00:41:43 +00:00
|
|
|
|
|
|
|
messageSchema.methods.toJson = function () {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
author: this.author,
|
|
|
|
content: this.content,
|
|
|
|
createdAt: this.createdAt
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-08-07 00:06:40 +00:00
|
|
|
|
2015-08-07 00:14:36 +00:00
|
|
|
messageSchema.statics.list = function (options, callback) {
|
2015-08-07 00:06:40 +00:00
|
|
|
return this.find().sort({createdAt: 1}).limit(30).exec(callback);
|
|
|
|
};
|
|
|
|
|
2015-08-05 00:41:43 +00:00
|
|
|
module.exports = mongoose.model('message', messageSchema);
|