person_chat.js 1.3 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 { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 个人聊天表
  8. const person_chat = {
  9. sender_id: { type: ObjectId, required: true }, // 发送人id
  10. sender_name: { type: String, required: false }, // 发送人名字
  11. receiver_id: { type: ObjectId, required: true }, // 接收人id
  12. receiver_name: { type: String, required: false }, // 接收人名字
  13. room_id: { type: ObjectId, required: true }, // 聊天房间id
  14. content: { type: String, required: true }, // 内容
  15. is_read: { type: Boolean, default: false }, // 是否已读
  16. send_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  17. };
  18. const schema = new Schema(person_chat, { toJSON: { virtuals: true } });
  19. schema.index({ id: 1 });
  20. schema.index({ sender_id: 1 });
  21. schema.index({ sender_name: 1 });
  22. schema.index({ receiver_id: 1 });
  23. schema.index({ receiver_name: 1 });
  24. schema.index({ 'meta.createdAt': 1 });
  25. schema.plugin(metaPlugin);
  26. module.exports = app => {
  27. const { mongoose } = app;
  28. return mongoose.model('Person_chat', schema, 'person_chat');
  29. };