소스 검색

增加按uid更新方法

liuyu 5 년 전
부모
커밋
9741117857
3개의 변경된 파일15개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      app/controller/user.js
  2. 1 0
      app/router.js
  3. 9 0
      app/service/user.js

+ 5 - 0
app/controller/user.js

@@ -22,6 +22,11 @@ class UserController extends Controller {
     const res = await this.service.querymenus(this.ctx.query);
     this.ctx.ok({ data: res });
   }
+
+  async updatebyuid() {
+    const res = await this.service.updatebyuid(this.ctx.params, this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = CrudController(UserController, meta);

+ 1 - 0
app/router.js

@@ -18,6 +18,7 @@ module.exports = app => {
   router.resources('user', '/api/auth/user', controller.user); // index、create、show、destroy
   router.post('user', '/api/auth/user/update/:id', controller.user.update);
   router.post('user', '/api/auth/user/uppasswd', controller.user.uppasswd);
+  router.post('/api/auth/user/updatebyuid/:id', controller.user.updatebyuid);
 
   // 机构表设置路由
   router.resources('dept', '/api/auth/dept', controller.dept); // index、create、show、destroy

+ 9 - 0
app/service/user.js

@@ -115,6 +115,15 @@ class UserService extends CrudService {
     return { id, menus: _menus };
   }
 
+  // 按条件更新方法
+  async updatebyuid({ id }, data) {
+    const user = await this.model.findOne({ uid: id });
+    if (user) {
+      user.name = data.name;
+    }
+    await user.save();
+  }
+
 }
 
 module.exports = UserService;