liuyu 4 years ago
parent
commit
8f2690ee1e
1 changed files with 6 additions and 0 deletions
  1. 6 0
      app/service/room.js

+ 6 - 0
app/service/room.js

@@ -11,6 +11,7 @@ class RoomService extends CrudService {
   constructor(ctx) {
     super(ctx, 'room');
     this.model = this.ctx.model.Room;
+    this.rumodel = this.ctx.model.Roomuser;
   }
 
   async create(data) {
@@ -19,6 +20,11 @@ class RoomService extends CrudService {
     if (room_) {
       throw new BusinessError('此房间已经存在,请重新输入');
     }
+    const roomuser = await this.rumodel.findById(data.anchorid);
+    if (!roomuser) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
+    }
+    data.username = roomuser.name;
     const res = await this.model.create(data);
     return res;
   }