user.js 1.2 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 { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
  5. // 用户表
  6. const user = {
  7. name: { type: String }, // 姓名
  8. phone: { type: String }, // 电话
  9. password: { type: Secret, select: false }, // 密码
  10. email: { type: String }, // 邮箱
  11. address: { type: String }, // 地址
  12. dept: { type: String }, // 部门
  13. zw: { type: String }, // 职务
  14. company: { type: String }, // 工作单位
  15. type: { type: String }, // 类型【0:管理员,1:商户,2:用户】
  16. openid: { type: String }, // 微信openid
  17. remark: { type: String },
  18. };
  19. const schema = new Schema(user, { toJSON: { virtuals: true } });
  20. schema.index({ id: 1 });
  21. schema.index({ name: 1 });
  22. schema.index({ phone: 1 });
  23. schema.index({ address: 1 });
  24. schema.index({ dept: 1 });
  25. schema.index({ zw: 1 });
  26. schema.index({ company: 1 });
  27. schema.index({ openid: 1 });
  28. schema.index({ type: 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. };