chat.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const moment = require('moment');
  5. // 群聊信息表
  6. const ChatSchema = {
  7. type: { type: String, required: false, maxLength: 200 }, // 类别0、医生1、患者
  8. sendid: { type: String, required: false, maxLength: 200 }, // 发送人ID
  9. sendname: { type: String, required: false, maxLength: 200 }, // 发送人姓名
  10. receiveid: { type: String, required: false, maxLength: 200 }, // 收件人ID
  11. receivename: { type: String, required: false, maxLength: 200 }, // 收件人姓名
  12. sendtime: { type: String, required: false, default: moment().format('YYYY-MM-DD HH:mm:ss') }, // 发送时间
  13. contenttype: { type: String, required: false, maxLength: 20 }, // 类别0、图片1、音频、2、视频、3、文字
  14. audiotime: { type: String, required: false, maxLength: 100 }, // 语音时长
  15. content: { type: String, required: false }, // 内容
  16. status: { type: String, required: false }, // 状态0、未读1、已读
  17. };
  18. const schema = new Schema(ChatSchema, { toJSON: { virtuals: true } });
  19. schema.index({ sendid: 1 });
  20. schema.index({ receiveid: 1 });
  21. schema.index({ 'meta.createdAt': 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('Chat', schema, 'chat');
  26. };