user.js 1.1 KB

123456789101112131415161718192021222324252627282930
  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, required: false, zh: '用户名' }, //
  8. phone: { type: String, required: false, zh: '手机号' }, //
  9. password: { type: Secret, required: false, select: false, zh: '密码' }, //
  10. icon: { type: Array, required: false, zh: '头像' }, //
  11. birth: { type: String, required: false, zh: '生日' }, //
  12. openid: { type: String, required: false, zh: '微信小程序' }, //
  13. status: { type: String, required: false, default: '0', zh: '状态' }, // 字典:user_type
  14. };
  15. const schema = new Schema(user, { toJSON: { getters: true, virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ 'meta.createdAt': 1 });
  18. schema.index({ name: 1 });
  19. schema.index({ phone: 1 });
  20. schema.index({ openid: 1 });
  21. schema.index({ status: 1 });
  22. schema.plugin(metaPlugin);
  23. module.exports = app => {
  24. const { mongoose } = app;
  25. return mongoose.model('User', schema, 'user');
  26. };