admin.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
  6. // 管理员表
  7. const admin = {
  8. name: { type: String }, // 名称
  9. phone: { type: String }, // 手机
  10. passwd: { type: Secret, select: false }, // 注册密码
  11. openid: { type: String }, // 微信openid
  12. role: { type: String }, // 角色: 0:超级管理员;1:管理员;2:机构管理员;3:业务管理员
  13. menus: { type: [ String ] }, // 菜单
  14. pid: { type: String }, // 上级id
  15. deptname: { type: String }, // 机构名称
  16. code: { type: String }, // 邀请码
  17. isdel: { type: Boolean, default: false }, // 是否删除
  18. remark: { type: String, maxLength: 200 },
  19. role_id: { type: String }, // 关联角色id
  20. };
  21. const schema = new Schema(admin, { toJSON: { virtuals: true } });
  22. schema.index({ id: 1 });
  23. schema.index({ name: 1 });
  24. schema.index({ phone: 1 });
  25. schema.index({ role: 1 });
  26. schema.index({ pid: 1 });
  27. schema.index({ code: 1 });
  28. schema.index({ role_id: 1 });
  29. schema.index({ 'meta.createdAt': 1 });
  30. schema.plugin(metaPlugin);
  31. module.exports = app => {
  32. const { mongoose } = app;
  33. return mongoose.model('Admin', schema, 'admin');
  34. };