user.js 1.2 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. mobile: { type: String, required: true, maxLength: 64 }, // 手机
  9. passwd: { type: Secret, select: false }, // 注册密码
  10. openid: { type: String, required: false }, // 微信openid
  11. unionid: { type: String, required: false }, // 微信unionid
  12. remark: { type: String, required: false }, // 备注
  13. type: { type: String, required: false, maxLength: 200 }, // 身份,0、中心管理元1、班主任用户2、学校用户3、教师4、学生
  14. uid: { type: String, required: false, maxLength: 200 }, // 关联用户信息id
  15. status: { type: String, required: false, default: '0' }, // 注册状态
  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. };