role.js 842 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const Role = {
  5. name: { type: String, required: true, maxLength: 200 }, // 角色名称
  6. type: { type: String, required: false, maxLength: 200 }, // 类型,每个项目有每个项目的设置,这里只存储,让各自项目记住自己类型对应什么
  7. menu: { type: Array, required: true }, // 菜单标题
  8. disabled: { type: Boolean, default: false }, // 使用状态
  9. params: { type: Object }, // 参数字段,需要就用,不需要就不用
  10. };
  11. const schema = new Schema(Role, {
  12. 'multi-tenancy': true,
  13. toJSON: { virtuals: true },
  14. });
  15. schema.index({ id: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('Role', schema, 'role');
  20. };