'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { ObjectId } = require('mongoose').Types; // 回复表 const reply = { name: { type: String }, icon: { type: String }, openid: { type: String }, content: { type: String }, reply_time: { type: String }, article_id: { type: ObjectId }, remark: { type: String, maxLength: 200 }, create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') }, }; const schema = new Schema(reply, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ name: 1 }); schema.index({ openid: 1 }); schema.index({ reply_time: 1 }); schema.index({ article_id: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Reply', schema, 'reply'); };