guhongwei il y a 2 ans
Parent
commit
d6c9f7f1c0
3 fichiers modifiés avec 8 ajouts et 11 suppressions
  1. 1 3
      app/controller/admin.js
  2. 1 1
      app/controller/config/.admin.js
  3. 6 7
      app/model/admin.js

+ 1 - 3
app/controller/admin.js

@@ -1,9 +1,7 @@
 'use strict';
 const meta = require('./config/.admin.js');
 const Controller = require('egg').Controller;
-const {
-  CrudController,
-} = require('naf-framework-mongoose-free/lib/controller');
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
 
 // 用户
 class AdminController extends Controller {

+ 1 - 1
app/controller/config/.admin.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["!account", "name", "!password"],
+    requestBody: ["account", "name", "password"],
   },
   destroy: {
     params: ["!id"],

+ 6 - 7
app/model/admin.js

@@ -1,21 +1,20 @@
 'use strict';
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
-
 const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
 
 // 用户
 const admin = {
-  account: { type: String, required: true, zh: '账号' }, //
-  name: { type: String, required: false, zh: '姓名' }, //
-  password: { type: Secret, required: true, select: false, zh: '密码' }, //
+  name: { type: String, zh: '昵称' },
+  account: { type: String, zh: '账号' },
+  password: { type: Secret, select: false, zh: '密码' }, //
 };
-const schema = new Schema(admin, { toJSON: { getters: true, virtuals: true } });
+const schema = new Schema(admin, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
+schema.index({ name: 1 });
+schema.index({ account: 1 });
 schema.index({ 'meta.createdAt': 1 });
-
 schema.plugin(metaPlugin);
-
 module.exports = app => {
   const { mongoose } = app;
   return mongoose.model('Admin', schema, 'admin');