user.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  5. // 用户表
  6. const UserSchema = {
  7. name: { type: String, required: false, maxLength: 200 }, // 名称
  8. phone: { type: String, required: true, maxLength: 64 }, // 手机
  9. passwd: { type: Secret, select: false }, // 注册密码
  10. openid: { type: String, required: false }, // 微信openid
  11. uid: { type: String, required: false }, // 用户信息id
  12. role: { type: String, required: false }, // 1-管理员,2-个人,3-企业管理员,4-子管理员,6、专家 7、临时用户
  13. menus: { type: [ String ], required: false }, // 菜单权限
  14. deptid: { type: String, required: false }, // 机构id
  15. remark: { type: String, required: false }, // 备注
  16. };
  17. const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
  18. schema.index({ openid: 1 });
  19. schema.index({ mobile: 1 });
  20. schema.plugin(metaPlugin);
  21. module.exports = app => {
  22. const { mongoose } = app;
  23. return mongoose.model('User', schema, 'user');
  24. };