guhongwei преди 2 години
родител
ревизия
992e87f808
променени са 5 файла, в които са добавени 16 реда и са изтрити 30 реда
  1. 1 1
      app/controller/config/.dictdata.js
  2. 1 0
      app/model/user.js
  3. 11 5
      app/service/user.js
  4. 3 3
      app/z_router/user.js
  5. 0 21
      package-lock.json

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

@@ -35,7 +35,7 @@ module.exports = {
     options: {
       query: ["skip", "limit"],
       sort: ["sort"],
-      desc: true,
+      desc: false,
       count: true,
     },
   },

+ 1 - 0
app/model/user.js

@@ -27,3 +27,4 @@ module.exports = app => {
   const { mongoose } = app;
   return mongoose.model('User', schema, 'user');
 };
+

+ 11 - 5
app/service/user.js

@@ -2,15 +2,21 @@
 const { CrudService } = require('naf-framework-mongoose-free/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
-const assert = require('assert');
-
+const Excel = require('exceljs');
 // 用户
-
 class UserService extends CrudService {
   constructor(ctx) {
     super(ctx, 'user');
     this.model = this.ctx.model.User;
   }
+  // async create(data) {
+  //   // TODO:保存数据
+  //   data = await this.beforeCreate(data);
+  //   console.log(data);
+  //   let res = await this.model.create(data);
+  //   res = await this.afterCreate(data, res);
+  //   return res;
+  // }
   async resetPwd({ id }, { password }) {
     const data = await this.model.findById(id);
     if (!data) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
@@ -26,8 +32,8 @@ class UserService extends CrudService {
   async login({ account, password }) {
     let user = await this.model.findOne({ account }, '+password');
     if (!user) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
-    const { password: upwd } = user;
-    // if (status !== '1') throw new BusinessError(ErrorCode.USER_NOT_BIND, '该账号处于禁止使用状态');
+    const { password: upwd, status, role_id } = user;
+    // if (status !== '1') { throw new BusinessError(ErrorCode.USER_NOT_BIND, '该账号处于禁止使用状态'); }
     if (password !== upwd.secret) { throw new BusinessError(ErrorCode.BAD_PASSWORD); }
     user = JSON.parse(JSON.stringify(user));
     delete user.meta;

+ 3 - 3
app/z_router/user.js

@@ -8,8 +8,8 @@ const routes = [
   { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
   { method: 'post', path: `/${rKey}/login`, controller: `${cKey}.login`, name: `${cKey}Login`, zh: `${zhKey}登陆` },
   { method: 'post', path: `/${rKey}/resetPwd/:id`, controller: `${cKey}.resetPwd`, name: `${cKey}ResetPwd`, zh: `重置密码${zhKey}` },
-  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
-  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, middleware: [ 'password' ], name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, middleware: [ 'password' ], name: `${cKey}Update`, zh: `修改${zhKey}` },
   { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
 ];
 
@@ -23,7 +23,7 @@ module.exports = app => {
     // 拼全路径
     const allPath = `${config.routePrefix}${path}`;
     // 处理中间件
-    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
     // 注册路由
     router[method](zh, allPath, ...middleware, ctl);
   }

+ 0 - 21
package-lock.json

@@ -8998,20 +8998,6 @@
       "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
       "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
     },
-    "node_modules/fsevents": {
-      "version": "2.3.2",
-      "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
-      "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
-      "dev": true,
-      "hasInstallScript": true,
-      "optional": true,
-      "os": [
-        "darwin"
-      ],
-      "engines": {
-        "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
-      }
-    },
     "node_modules/fstream": {
       "version": "1.0.12",
       "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz",
@@ -25095,13 +25081,6 @@
       "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
       "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
     },
-    "fsevents": {
-      "version": "2.3.2",
-      "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
-      "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
-      "dev": true,
-      "optional": true
-    },
     "fstream": {
       "version": "1.0.12",
       "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz",