admin.js 938 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 admin = {
  7. account: { type: String, required: false, zh: '账号' }, //
  8. password: { type: Secret, required: false, select: false, zh: '密码' }, //
  9. role: { type: String, zh: '角色', ref: 'Dev.Role' },
  10. shop: { type: String, zh: '店铺', ref: 'Shop.Shop' },
  11. name: { type: String, required: false, zh: '名称' }, //
  12. email: { type: String, required: false, zh: '邮箱' }, //
  13. };
  14. const schema = new Schema(admin, { toJSON: { getters: true, virtuals: true } });
  15. schema.index({ id: 1 });
  16. schema.index({ 'meta.createdAt': 1 });
  17. schema.index({ account: 1 });
  18. schema.plugin(metaPlugin);
  19. module.exports = app => {
  20. const { mongoose } = app;
  21. return mongoose.model('Admin', schema, 'admin');
  22. };