person_room.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/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 个人聊天房间表
  8. const person_room = {
  9. product_id: { type: ObjectId }, // 产品
  10. p1_id: { type: ObjectId, required: true }, // 第一个人id
  11. p1: { type: String, required: false }, // 第一个人名
  12. p2_id: { type: ObjectId, required: true }, // 第二个人id
  13. p2: { type: String, required: false }, // 第二个人名
  14. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  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('Person_room', schema, 'person_room');
  27. };