user.js 820 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. name: { type: String, required: false, maxLength: 200 }, // 名称
  8. mobile: { type: String, required: true, maxLength: 64 }, // 手机
  9. passwd: { type: Secret, select: false }, // 注册密码
  10. openid: { type: String, required: false }, // 微信openid
  11. remark: { type: String, required: false }, // 备注
  12. };
  13. const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
  14. schema.index({ openid: 1 });
  15. schema.index({ mobile: 1 });
  16. schema.plugin(metaPlugin);
  17. module.exports = app => {
  18. const { mongoose } = app;
  19. return mongoose.model('User', schema, 'user');
  20. };