news.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 文件链接
  8. const filelinks = new Schema({
  9. title: { type: String, required: false, maxLength: 500 }, // 名称,
  10. url: { type: String, required: false, maxLength: 500 }, // 链接地址,
  11. });
  12. // 信息表
  13. const news = {
  14. user_id: { type: ObjectId },
  15. column_id: { type: String, required: false, maxLength: 500 }, // 栏目id
  16. column_name: { type: String, required: false, maxLength: 500 }, // 栏目名称
  17. title: { type: String, required: false, maxLength: 500 }, // 标题
  18. publish_time: { type: String, required: false, maxLength: 500 }, // 时间
  19. origin: { type: String, required: false, maxLength: 500, default: '网站管理员' }, // 来源
  20. brief: { type: String, maxLength: 300 }, // 简介
  21. picture: { type: Object, required: false }, // 图片
  22. filepath: { type: Object, required: false }, // 附件
  23. video: { type: Object }, // 视频
  24. content: { type: String, required: false }, // 正文内容
  25. type: { type: String, required: false, maxLength: 200 }, // 类型,国家,科学院
  26. remark: { type: String, maxLength: 200 },
  27. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  28. };
  29. const schema = new Schema(news, { toJSON: { virtuals: true } });
  30. schema.index({ id: 1 });
  31. schema.index({ title: 1 });
  32. schema.index({ 'meta.createdAt': 1 });
  33. schema.plugin(metaPlugin);
  34. module.exports = app => {
  35. const { mongoose } = app;
  36. return mongoose.model('News', schema, 'news');
  37. };