admin.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. password: { type: Secret, select: false }, // 注册密码
  11. openid: { type: String }, // 微信openid
  12. role: { type: String }, // 角色: 0:超级管理员;1:管理员;2:机构管理员;3:业务管理员
  13. pid: { type: String }, // 上级id
  14. deptname: { type: String }, // 机构名称
  15. code: { type: String }, // 邀请码
  16. remark: { type: String, maxLength: 200 },
  17. role_id: { type: String }, // 关联角色id
  18. };
  19. const schema = new Schema(admin, { toJSON: { virtuals: true } });
  20. schema.index({ id: 1 });
  21. schema.index({ name: 1 });
  22. schema.index({ phone: 1 });
  23. schema.index({ role: 1 });
  24. schema.index({ pid: 1 });
  25. schema.index({ code: 1 });
  26. schema.index({ role_id: 1 });
  27. schema.index({ 'meta.createdAt': 1 });
  28. schema.plugin(metaPlugin);
  29. module.exports = app => {
  30. const { mongoose } = app;
  31. return mongoose.model('Admin', schema, 'admin');
  32. };