logs.js 973 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const Logs = {
  6. ip: { type: String, required: true, maxLength: 200 },
  7. userid: { type: String, required: true, maxLength: 200 }, // 操作
  8. name: { type: String, required: false, maxLength: 200 }, // 用户
  9. route: { type: String, required: false, maxLength: 200 }, // 路由
  10. method: { type: String, required: false, maxLength: 200 }, // 用户
  11. params: { type: Object, required: false }, // 参数
  12. opera: { type: String, required: false }, // 操作
  13. time: { type: String, required: false, maxLength: 200, default: moment().format('YYYY-MM-DD HH:mm:ss') }, // 时间
  14. };
  15. const schema = new Schema(Logs, { toJSON: { virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.plugin(metaPlugin);
  18. module.exports = app => {
  19. const { mongoose } = app;
  20. return mongoose.model('Logs', schema, 'logs');
  21. };