reloaded 4 سال پیش
والد
کامیت
3335e24642
4فایلهای تغییر یافته به همراه22 افزوده شده و 20 حذف شده
  1. 0 4
      app/controller/lookuser.js
  2. 4 1
      app/controller/room.js
  3. 0 13
      app/service/lookuser.js
  4. 18 2
      app/service/room.js

+ 0 - 4
app/controller/lookuser.js

@@ -13,10 +13,6 @@ class LookuserController extends Controller {
     this.service = this.ctx.service.lookuser;
   }
 
-  async index() {
-    const data = await this.service.query(this.ctx.query);
-    this.ctx.ok({ ...data });
-  }
 }
 
 module.exports = CrudController(LookuserController, meta);

+ 4 - 1
app/controller/room.js

@@ -6,7 +6,6 @@ const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 class RoomController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.room;
@@ -17,6 +16,10 @@ class RoomController extends Controller {
     this.ctx.ok({ data: res });
   }
 
+  async index() {
+    const data = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...data });
+  }
 }
 
 module.exports = CrudController(RoomController, meta);

+ 0 - 13
app/service/lookuser.js

@@ -11,7 +11,6 @@ class LookuserService extends CrudService {
   constructor(ctx) {
     super(ctx, 'lookuser');
     this.model = this.ctx.model.Lookuser;
-    this.rmodel = this.ctx.model.Room;
   }
 
   async create(data) {
@@ -22,18 +21,6 @@ class LookuserService extends CrudService {
     }
   }
 
-  async query({ skip, limit, ...info }) {
-    const total = await this.rmodel.count(info);
-    const rooms = await this.rmodel.find(info).skip(Number(skip)).limit(Number(limit));
-    const data = [];
-    for (const _room of rooms) {
-      const room = _.cloneDeep(JSON.parse(JSON.stringify(_room)));
-      const number = await this.model.count({ roomid: room._id });
-      room.number = number;
-      data.push(room);
-    }
-    return { data, total };
-  }
 
 }
 

+ 18 - 2
app/service/room.js

@@ -9,16 +9,17 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 
 class RoomService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'room');
+    super(ctx, "room");
     this.model = this.ctx.model.Room;
     this.rumodel = this.ctx.model.Roomuser;
+    this.lookmodel = this.ctx.model.Lookuser;
   }
 
   async create(data) {
     const { name } = data;
     const room_ = await this.model.findOne({ name });
     if (room_) {
-      throw new BusinessError('此房间已经存在,请重新输入');
+      throw new BusinessError("此房间已经存在,请重新输入");
     }
     const roomuser = await this.rumodel.findById(data.anchorid);
     if (!roomuser) {
@@ -35,6 +36,21 @@ class RoomService extends CrudService {
     return res;
   }
 
+  async query({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const rooms = await this.model
+      .find(info)
+      .skip(Number(skip))
+      .limit(Number(limit));
+    const data = [];
+    for (const _room of rooms) {
+      const room = _.cloneDeep(JSON.parse(JSON.stringify(_room)));
+      const number = await this.lookmodel.count({ roomid: room._id });
+      room.number = number;
+      data.push(room);
+    }
+    return { data, total };
+  }
 }
 
 module.exports = RoomService;