article.js 990 B

12345678910111213141516171819202122232425262728
  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. // 文章表
  6. const article = {
  7. title: { type: String }, // 标题
  8. user: { type: String }, // 医生
  9. user_id: { type: String }, // 医生id
  10. origin: { type: String }, // 来源
  11. img_url: { type: String }, // 图片
  12. brief: { type: String }, // 简介
  13. content: { type: String }, // 内容
  14. file_url: { type: String }, // 附件
  15. remark: { type: String, maxLength: 200 },
  16. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  17. };
  18. const schema = new Schema(article, { toJSON: { virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ title: 1 });
  21. schema.index({ user: 1 });
  22. schema.index({ user_id: 1 });
  23. schema.index({ 'meta.createdAt': 1 });
  24. schema.plugin(metaPlugin);
  25. module.exports = app => {
  26. const { mongoose } = app;
  27. return mongoose.model('Article', schema, 'article');
  28. };