'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose-free/lib/model/schema'); const { ObjectId } = require('mongoose').Types; // 个人聊天表 const person_chat = { sender_id: { type: String, required: true }, // 发送人id sender_name: { type: String, required: false }, // 发送人名字 receiver_id: { type: String, required: true }, // 接收人id receiver_name: { type: String, required: false }, // 接收人名字 room_id: { type: String, required: true }, // 聊天房间id content: { type: String, required: true }, // 内容 is_read: { type: Boolean, default: false }, // 是否已读 send_time: { type: String }, }; const schema = new Schema(person_chat, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ sender_id: 1 }); schema.index({ sender_name: 1 }); schema.index({ receiver_id: 1 }); schema.index({ receiver_name: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('PersonChat', schema, 'personChat'); };