user.js 890 B

12345678910111213141516171819202122
  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: true, maxLength: 200 }, // 用户名称
  8. mobile: { type: String, required: true, maxLength: 200 }, // 手机号
  9. password: { type: Secret, select: false }, // 密码
  10. dept_id: { type: String, required: false, maxLength: 200 }, // 部门id
  11. gender: { type: String, required: false, maxLength: 200 }, // 性别
  12. remark: { type: String, required: false, maxLength: 200 }, // 备注
  13. };
  14. const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('User', schema, 'user');
  20. };