role.js 587 B

123456789101112131415161718
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const { ObjectId } = require('mongoose').Types;
  5. // 角色表
  6. const role = {
  7. name: { type: String, zh: '名称' },
  8. code: { type: String, zh: '编码' },
  9. remark: { type: String },
  10. };
  11. const schema = new Schema(role, { toJSON: { virtuals: true } });
  12. schema.index({ id: 1 });
  13. schema.index({ 'meta.createdAt': 1 });
  14. schema.plugin(metaPlugin);
  15. module.exports = app => {
  16. const { mongoose } = app;
  17. return mongoose.model('Role', schema, 'role');
  18. };