'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_room = { product_id: { type: String }, // 产品 p1_id: { type: String, required: true }, // 第一个人id p1: { type: String, required: false }, // 第一个人名 p2_id: { type: String, required: true }, // 第二个人id p2: { type: String, required: false }, // 第二个人名 create_time: { type: String }, last_time: { type: String }, // 最后发言时间 }; const schema = new Schema(person_room, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ product_id: 1 }); schema.index({ p1_id: 1 }); schema.index({ p2_id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('PersonRoom', schema, 'personRoom'); };