user.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
  6. // 用户表(分站模式)
  7. const user = {
  8. phone: { type: String, required: false }, // 手机号
  9. password: { type: Secret, select: false }, // 密码
  10. type: { type: String, required: false }, // 用户类型
  11. icon: { type: Array, required: false }, // 头像
  12. nickname: { type: String, required: false }, // 昵称
  13. gender: { type: String, required: false }, // 性别
  14. work: { type: String, required: false }, // 岗位
  15. mechanism: { type: String, required: false }, // 机构
  16. email: { type: String, required: false }, // 邮箱
  17. status: { type: String, required: false, default: '0' }, // 状态,0-待审,1:审核通过,2:审核拒绝
  18. // account: { type: String, required: false }, // 账号
  19. // uid: { type: String }, // 关联id,与各自业务有关的用户id
  20. remark: { type: String },
  21. };
  22. const schema = new Schema(user, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  23. schema.index({ id: 1 });
  24. schema.index({ phone: 1 });
  25. schema.index({ type: 1 });
  26. schema.index({ gender: 1 });
  27. schema.index({ status: 1 });
  28. schema.index({ 'meta.createdAt': 1 });
  29. schema.plugin(metaPlugin);
  30. module.exports = app => {
  31. const { mongoose } = app;
  32. return mongoose.model('User', schema, 'user');
  33. };