user.js 1004 B

12345678910111213141516171819202122232425262728
  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. };
  14. const schema = new Schema(user, { toJSON: { getters: true, virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.index({ 'meta.createdAt': 1 });
  17. schema.index({ name: 1 });
  18. schema.index({ phone: 1 });
  19. schema.index({ openid: 1 });
  20. schema.plugin(metaPlugin);
  21. module.exports = app => {
  22. const { mongoose } = app;
  23. return mongoose.model('User', schema, 'user');
  24. };