user.js 954 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. // 用户表
  6. const UserSchema = {
  7. uid: { type: String, required: false, maxLength: 200 }, // 用户信息表id
  8. openid: { type: String, required: false, maxLength: 200 }, // 用户微信openid
  9. passwd: { type: { Secret }, required: true, select: false, maxLength: 200 }, // 用户密码
  10. role_id: { type: String, required: false, maxLength: 200 }, // 用户权限id
  11. name: { type: String, required: false, maxLength: 200 }, // 用户名
  12. phone: { type: String, required: true, maxLength: 64 }, // 手机号
  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. };