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