user.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  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. name: { type: String, required: false }, // 名称
  9. phone: { type: String, required: false }, // 手机号
  10. password: { type: Secret, select: false }, // 密码
  11. card: { type: String, required: false }, // 身份证
  12. email: { type: String, required: false }, // 邮箱
  13. addr: { type: String, required: false }, // 地址
  14. school: { type: String, required: false }, // 院系
  15. major: { type: String, required: false }, // 专业
  16. zwzc: { type: String, required: false }, // 职务职称
  17. office_phone: { type: String, required: false }, // 办公电话
  18. profession: { type: String, required: false }, // 所属行业
  19. status: { type: String, required: false, default: '0' }, // 状态,0-待审,1:审核通过,2:审核拒绝
  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({ card: 1 });
  26. schema.index({ major: 1 });
  27. schema.index({ school: 1 });
  28. schema.index({ status: 1 });
  29. schema.index({ 'meta.createdAt': 1 });
  30. schema.plugin(metaPlugin);
  31. module.exports = app => {
  32. const { mongoose } = app;
  33. return mongoose.model('User', schema, 'user');
  34. };