news.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { ObjectId } = require('mongoose').Types;
  6. // 新闻表
  7. const news = {
  8. user_id: { type: ObjectId },
  9. column_name: { type: String }, // 栏目名称
  10. title: { type: String }, // 标题
  11. release_time: { type: String }, // 发布时间
  12. origin: { type: String }, // 来源
  13. content: { type: String }, // 内容
  14. image: { type: Array }, // 图片
  15. fileUrl: { type: Array }, // 附件
  16. remark: { type: String },
  17. create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
  18. };
  19. const image = {
  20. name: { type: String, zh: '名称' },
  21. url: { type: String, zh: '地址' },
  22. };
  23. const schema = new Schema(news, { toJSON: { virtuals: true } });
  24. schema.index({ id: 1 });
  25. schema.index({ user_id: 1 });
  26. schema.index({ column_name: 1 });
  27. schema.index({ origin: 1 });
  28. schema.index({ title: 1 });
  29. schema.index({ release_time: 1 });
  30. schema.index({ 'meta.createdAt': 1 });
  31. schema.plugin(metaPlugin);
  32. module.exports = app => {
  33. const { mongoose } = app;
  34. return mongoose.model('News', schema, 'news');
  35. };