service.js 1.2 KB

1234567891011121314151617181920212223242526272829
  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 service = {
  8. user_id: { type: ObjectId },
  9. title: { type: String }, // 标题
  10. origin: { type: String }, // 来源
  11. renew_time: { type: String }, // 更新时间
  12. type: { type: String }, // 类型:0=>文字;1=>图文;2=>科普视频;3=>培训视频
  13. content: { type: String }, // 内容
  14. imgUrl: { type: Array }, // 图片 [{url:uri}]
  15. fileUrl: { type: Array }, // 视频 [{url:uri}]
  16. contact: { type: Object }, // 服务联系人:name-姓名;phone-联系电话;email-电子邮箱;address-联系地址
  17. read: { type: Number, default: 0 }, // 阅读数
  18. remark: { type: String, maxLength: 200 },
  19. create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
  20. };
  21. const schema = new Schema(service, { toJSON: { virtuals: true } });
  22. schema.index({ id: 1 });
  23. schema.index({ user_id: 1 });
  24. schema.index({ 'meta.createdAt': 1 });
  25. schema.plugin(metaPlugin);
  26. module.exports = app => {
  27. const { mongoose } = app;
  28. return mongoose.model('Service', schema, 'service');
  29. };