'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 opera = { user_id: { type: ObjectId, required: true }, // 操作人 target: { type: ObjectId, required: true }, // 目标id target_model: { type: String, required: true }, // 目标model method: { type: String, required: true }, // 执行函数, 之后自定义列表去换成人话 remark: { type: String }, // 操作时间转过来 }; const schema = new Schema(opera, { 'multi-tenancy': true, toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ user_id: 1 }); schema.index({ target: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Opera', schema, 'opera'); };