admin.js 712 B

12345678910111213141516171819
  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, default: '系统管理员' }, // 显示名称
  8. account: { type: String }, // 账号
  9. password: { type: Secret, select: false }, // 密码
  10. remark: { type: String },
  11. };
  12. const schema = new Schema(admin, { toJSON: { virtuals: true } });
  13. schema.index({ id: 1 });
  14. schema.index({ 'meta.createdAt': 1 });
  15. schema.plugin(metaPlugin);
  16. module.exports = app => {
  17. const { mongoose } = app;
  18. return mongoose.model('Admin', schema, 'admin');
  19. };