liuyu 4 년 전
부모
커밋
14b3bf89f2
2개의 변경된 파일28개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      app/controller/lookuser.js
  2. 23 0
      app/service/lookuser.js

+ 5 - 0
app/controller/lookuser.js

@@ -13,6 +13,11 @@ class LookuserController extends Controller {
     this.service = this.ctx.service.lookuser;
   }
 
+  async update() {
+    const res = await this.service.update(this.ctx.params, this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
   async roomcount() {
     const data = await this.service.roomcount(this.ctx.query);
     this.ctx.ok({ ...data });

+ 23 - 0
app/service/lookuser.js

@@ -21,6 +21,29 @@ class LookuserService extends CrudService {
     }
   }
 
+  async update({ id }, data) {
+    const { switchrole } = data;
+    const lookuser = await this.model.findById(id);
+    if (!lookuser) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
+    }
+    lookuser.switchrole = switchrole;
+    const res = await lookuser.save();
+    if (res) {
+      const { mq } = this.ctx;
+      if (mq) {
+        const exchange = 'switch_role_' + res.userid;
+        const parm = {
+          durable: true,
+          headers: {
+            userid: res.userid,
+          } };
+        await mq.fanout(exchange, res.userid, JSON.stringify(res), parm);
+      }
+    }
+    return res;
+  }
+
   async roomcount(data) {
     const { roomname } = data;
     const total = await this.model.count({ roomname });