1234567891011121314151617181920212223242526272829 |
- 'use strict';
- const Schema = require('mongoose').Schema;
- const moment = require('moment');
- const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
- const { Secret } = require('naf-framework-mongoose/lib/model/schema');
- const { ObjectId } = require('mongoose').Types;
- // 个人聊天表
- const person_chat = {
- sender_id: { type: ObjectId, required: true }, // 发送人id
- sender_name: { type: String, required: false }, // 发送人名字
- receiver_id: { type: ObjectId, required: true }, // 接收人id
- receiver_name: { type: String, required: false }, // 接收人名字
- room_id: { type: ObjectId, required: true }, // 聊天房间id
- content: { type: String, required: true }, // 内容
- is_read: { type: Boolean, default: false }, // 是否已读
- send_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
- };
- 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('Person_chat', schema, 'person_chat');
- };
|