admin.js 781 B

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