Browse Source

修改bug

asd123a20 3 years ago
parent
commit
5f760bb8a5
1 changed files with 8 additions and 7 deletions
  1. 8 7
      app/service/adminUser.js

+ 8 - 7
app/service/adminUser.js

@@ -28,9 +28,11 @@ class adminUserService extends Service {
     assert(_id, 'id不存在');
     const { AdminUser: model } = this.ctx.model;
     try {
-      const hash = crypto.createHmac('sha256', this.app.config.userSecret);
-      const pwd = hash.update(password).digest('hex');
-      await model.findById(_id).update({ userName, phone, roleList, state, password: pwd });
+      if (password) {
+        const hash = crypto.createHmac('sha256', this.app.config.userSecret);
+        password = hash.update(password).digest('hex');
+      }
+      await model.findById(_id).update({ userName, phone, roleList, state, password });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       console.log(error);
@@ -38,7 +40,6 @@ class adminUserService extends Service {
     }
   }
   async pwdUpdate({ password, userName, confirmPwd }) {
-    console.log(password, userName, confirmPwd);
     assert(userName, '用户名不存在');
     const { AdminUser: model } = this.ctx.model;
     const hash = crypto.createHmac('sha256', this.app.config.userSecret);
@@ -49,8 +50,8 @@ class adminUserService extends Service {
         return { errmsg: '原密码错误', errcode: -2003 };
       }
       const hash = crypto.createHmac('sha256', this.app.config.userSecret);
-      const pwd = hash.update(password).digest('hex');
-      await model.findByIdAndUpdate(res._id, { password: pwd });
+      password = hash.update(password).digest('hex');
+      await model.findByIdAndUpdate(res._id, { password });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error('修改失败');
@@ -60,7 +61,7 @@ class adminUserService extends Service {
     assert(id, 'id不存在');
     const { AdminUser: model } = this.ctx.model;
     try {
-      await model.findById(id).remove();
+      await model.remove({ _id: id });
       return { errmsg: '', errcode: 0 };
     } catch (error) {
       throw new Error('删除失败');