news.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * 新闻信息
  3. */
  4. 'use strict';
  5. const Schema = require('mongoose').Schema;
  6. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  7. // 附件信息
  8. const Attachment = new Schema({
  9. name: { type: String, maxLength: 128 },
  10. uri: { type: String, maxLength: 128 },
  11. }, { _id: false });
  12. // 新闻信息
  13. const SchemaDefine = {
  14. column: { type: String, required: true, maxLength: 64 }, // 栏目
  15. site: { type: String, required: true, maxLength: 64 }, // 分站
  16. title: { type: String, required: true, maxLength: 128 }, // 标题
  17. content: { type: String, required: true, maxLength: 102400, select: false }, // 内容详情
  18. picurl: { type: String, required: false, maxLength: 256 }, // 标题图片URL
  19. top: { type: Number, required: true, default: 0 }, // 置顶
  20. tags: [{ type: String, maxLength: 64 }], // 标签
  21. attachment: [ Attachment ], // 附件
  22. issuer: String, // 发文单位
  23. meta: {
  24. createdBy: String, // 创建用户
  25. updatedBy: String, // 修改用户
  26. },
  27. remark: { type: String, maxLength: 500 }, // 备注
  28. };
  29. const schema = new Schema(SchemaDefine, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  30. schema.plugin(metaPlugin);
  31. schema.index({ column: 1 });
  32. schema.index({ 'meta.state': 1 });
  33. schema.index({ 'meta.createdAt': -1 });
  34. schema.index({ 'meta.createdAt': -1, top: -1, 'meta.state': 1 });
  35. module.exports = app => {
  36. const { mongoose } = app;
  37. return mongoose.model('NewsInfo', schema, 'cms_news');
  38. };