nodeclub/models/base_model.js
Jason Lee 1618b2119c 增加 BaseModel,用 mongoose plugin 的方式为每个 Model 扩展 static, instance 函数;
发现有许多转换 create_at, updated_at 的动作,移到 BaseModel 里面,简化代码;
2015-05-23 21:25:09 +08:00

15 lines
371 B
JavaScript

/**
* 给所有的 Model 扩展功能
* http://mongoosejs.com/docs/plugins.html
*/
var tools = require('../common/tools');
module.exports = function(schema) {
schema.methods.create_at_ago = function() {
return tools.formatDate(this.create_at, true);
}
schema.methods.updated_at_ago = function() {
return tools.formatDate(this.create_at, true);
};
}