admin.js 1.0 KB

123456789101112131415161718192021222324
  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 admin = {
  7. name: { type: String, required: true }, // 用户名
  8. phone: { type: String, required: false, maxLength: 200 }, // 电话号码
  9. password: { type: Secret, required: true, select: false }, // 登录密码
  10. card: { type: String, required: false, maxLength: 200 }, // 身份证号
  11. email: { type: String, required: false, maxLength: 200 }, // 邮箱
  12. addr: { type: String, required: false, maxLength: 500 }, // 地址
  13. remark: { type: String, maxLength: 200 },
  14. };
  15. const schema = new Schema(admin, { toJSON: { virtuals: true } });
  16. schema.index({ id: 1 });
  17. schema.index({ phone: 1 });
  18. schema.index({ card: 1 });
  19. schema.index({ 'meta.createdAt': 1 });
  20. schema.plugin(metaPlugin);
  21. module.exports = app => {
  22. const { mongoose } = app;
  23. return mongoose.model('Admin', schema, 'admin');
  24. };