news.js 961 B

123456789101112131415161718192021222324252627
  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. title: { type: String }, // 标题
  9. origin: { type: String }, // 来源
  10. create_time: { type: String }, // 时间
  11. content: { type: String }, // 内容
  12. img: { type: Array }, // 图片,1张
  13. type: { type: String, default: '0' }, // 类型:0-国内新闻;1-健康咨询
  14. brief: { type: String }, // 简介
  15. remark: { type: String },
  16. };
  17. const schema = new Schema(news, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  18. schema.index({ id: 1 });
  19. schema.index({ title: 1 });
  20. schema.index({ type: 1 });
  21. schema.index({ create_time: 1 });
  22. schema.index({ 'meta.createdAt': 1 });
  23. schema.plugin(metaPlugin);
  24. module.exports = app => {
  25. const { mongoose } = app;
  26. return mongoose.model('News', schema, 'news');
  27. };