user.js 1.1 KB

12345678910111213141516171819202122232425
  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. userid: { type: String, required: false, maxLength: 200 }, // 用户信息表id
  8. openid: { type: String, required: false, maxLength: 200 }, // 用户微信openid
  9. passwd: { type: { Secret }, required: true, select: false, maxLength: 200 }, // 用户密码
  10. role_id: { type: String, required: false, maxLength: 200 }, // 用户权限id
  11. name: { type: String, required: false, maxLength: 200 }, // 用户名
  12. phone: { type: String, required: true, maxLength: 64 }, // 手机号
  13. type: { type: String, required: false, maxLength: 200 }, // 用户类型,0-超级管理员,1-管理员,2-专家,3-普通用户,4-计算中心职员
  14. };
  15. const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.plugin(metaPlugin);
  18. module.exports = app => {
  19. const { mongoose } = app;
  20. return mongoose.model('User', schema, 'user');
  21. };