user.js 904 B

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