Content.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Created by Administrator on 2015/4/15.
  3. * 管理员用户组对象
  4. */
  5. var mongoose = require('mongoose');
  6. var Schema = mongoose.Schema;
  7. var shortid = require('shortid');
  8. var ContentCategory = require('./ContentCategory');
  9. var AdminUser = require('./AdminUser');
  10. var ContentSchema = new Schema({
  11. _id: {
  12. type: String,
  13. unique: true,
  14. 'default': shortid.generate
  15. },
  16. title: String,
  17. stitle : String,
  18. type: { type: String, default: "content" }, // 发布形式 默认为普通文档,约定 singer 为单页面文档
  19. category : { type : String , ref : 'ContentCategory'}, //文章类别
  20. sortPath : String, //存储所有父节点结构
  21. tags : String, // 标签
  22. keywords : String,
  23. sImg : { type: String, default: "/upload/images/defaultImg.jpg" }, // 文章小图
  24. discription : String,
  25. date: { type: Date, default: Date.now },
  26. updateDate: { type: Date, default: Date.now }, // 更新时间
  27. author : { type: String , ref : 'AdminUser'}, // 文档作者
  28. state : { type: Boolean, default: true }, // 是否在前台显示,默认显示
  29. isTop : { type: Number, default: 0 }, // 是否推荐,默认不推荐 0为不推荐,1为推荐
  30. clickNum : { type: Number, default: 1 },
  31. comments : {},
  32. commentNum : { type: Number, default: 0 }, // 评论数
  33. likeNum : { type: Number, default: 0 }, // 喜欢数
  34. likeUserIds : String, // 喜欢该文章的用户ID集合
  35. from : { type: String, default: '1' }, // 来源 1为原创 2为转载
  36. // 插件信息相关属性
  37. repositoryPath : String, // git 知识库路径
  38. downPath : String, // git 项目下载地址
  39. previewPath : String // 插件预览地址
  40. });
  41. ContentSchema.statics = {
  42. //更新评论数
  43. updateCommentNum : function(contentId,key,callBack){
  44. Content.findOne({'_id' : contentId},'commentNum',function(err,doc){
  45. if(err){
  46. res.end(err)
  47. }
  48. if(key === 'add'){
  49. doc.commentNum = doc.commentNum + 1;
  50. }else if(key === 'del'){
  51. doc.commentNum = doc.commentNum - 1;
  52. }
  53. doc.save(function(err){
  54. if(err) throw err;
  55. callBack();
  56. })
  57. })
  58. }
  59. };
  60. var Content = mongoose.model("Content",ContentSchema);
  61. module.exports = Content;