topic.js 1.0 KB

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 topic = {
  8. user_id: { type: ObjectId },
  9. content: { type: String }, // 内容
  10. origin: { type: String }, // 来源
  11. renew_time: { type: String }, // 更新时间
  12. type: { type: String }, // 类型:0=>图文;1=>视频
  13. imgUrl: { type: Array }, // 图片
  14. fileUrl: { type: Array }, // 视频
  15. website: { type: String }, // 网址
  16. read: { type: Number, default: 0 }, // 阅读数
  17. remark: { type: String, maxLength: 200 },
  18. create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
  19. };
  20. const schema = new Schema(topic, { toJSON: { virtuals: true } });
  21. schema.index({ id: 1 });
  22. schema.index({ 'meta.createdAt': 1 });
  23. schema.plugin(metaPlugin);
  24. module.exports = app => {
  25. const { mongoose } = app;
  26. return mongoose.model('Topic', schema, 'topic');
  27. };