personRoom.js 1.1 KB

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 个人聊天房间表
  8. const person_room = {
  9. product_id: { type: String }, // 产品
  10. p1_id: { type: String, required: true }, // 第一个人id
  11. p1: { type: String, required: false }, // 第一个人名
  12. p2_id: { type: String, required: true }, // 第二个人id
  13. p2: { type: String, required: false }, // 第二个人名
  14. create_time: { type: String },
  15. last_time: { type: String }, // 最后发言时间
  16. };
  17. const schema = new Schema(person_room, { toJSON: { virtuals: true } });
  18. schema.index({ id: 1 });
  19. schema.index({ product_id: 1 });
  20. schema.index({ p1_id: 1 });
  21. schema.index({ p2_id: 1 });
  22. schema.index({ 'meta.createdAt': 1 });
  23. schema.plugin(metaPlugin);
  24. module.exports = app => {
  25. const { mongoose } = app;
  26. return mongoose.model('PersonRoom', schema, 'personRoom');
  27. };