user.js 986 B

123456789101112131415161718192021222324
  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. const User = {
  6. name: { type: String, required: true, maxLength: 200 }, // 用户名
  7. login_id: { type: String, required: true, maxLength: 200 }, // 登陆id
  8. role: { type: String, required: false, maxLength: 200 }, // 角色
  9. password: { type: Secret, select: false },
  10. status: { type: String, default: '0' }, // 使用状态: 0=>使用中;1=>冻结;2=>异常
  11. params: { type: Object }, // 参数字段,需要就用,不需要就不用
  12. };
  13. const schema = new Schema(User, { 'multi-tenancy': true, toJSON: { virtuals: true } });
  14. schema.index({ id: 1 });
  15. schema.plugin(metaPlugin);
  16. schema.index({ _tenant: 1 });
  17. schema.index({ name: 1 });
  18. schema.index({ login_id: 1 });
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('Users', schema, 'user');
  22. };