'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const Logs = { ip: { type: String, required: true, maxLength: 200 }, userid: { type: String, required: true, maxLength: 200 }, // 操作 name: { type: String, required: false, maxLength: 200 }, // 用户 route: { type: String, required: false, maxLength: 200 }, // 路由 method: { type: String, required: false, maxLength: 200 }, // 用户 params: { type: Object, required: false }, // 参数 opera: { type: String, required: false }, // 操作 time: { type: String, required: false, maxLength: 200, default: moment().format('YYYY-MM-DD HH:mm:ss') }, // 时间 }; const schema = new Schema(Logs, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Logs', schema, 'logs'); };