123456789101112131415161718192021222324252627 |
- '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_room = {
- product_id: { type: ObjectId }, // 产品
- p1_id: { type: ObjectId, required: true }, // 第一个人id
- p1: { type: String, required: false }, // 第一个人名
- p2_id: { type: ObjectId, required: true }, // 第二个人id
- p2: { type: String, required: false }, // 第二个人名
- create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
- 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('Person_room', schema, 'person_room');
- };
|