liuyu 4 年之前
父節點
當前提交
3aa2a52819
共有 3 個文件被更改,包括 14 次插入2 次删除
  1. 3 2
      app/controller/.room.js
  2. 1 0
      app/model/room.js
  3. 10 0
      app/service/room.js

+ 3 - 2
app/controller/.room.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["name", "type", "filedir", "url", "anchorid"],
+    requestBody: ["name", "type", "filedir", "url", "anchorid","status"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["name", "type", "filedir", "url", "anchorid"],
+    requestBody: ["name", "type", "filedir", "url", "anchorid","status"],
   },
   show: {
     parameters: {
@@ -23,6 +23,7 @@ module.exports = {
         type: "type",
         filedir: "filedir",
         url: "url",
+        status: "status",
         anchorid: "anchorid",
       },
     },

+ 1 - 0
app/model/room.js

@@ -8,6 +8,7 @@ const RoomSchema = {
   filedir: { type: String, required: false, maxLength: 200 }, // 封面图片
   url: { type: String, required: false, maxLength: 200 }, // 房间地址
   anchorid: { type: String, required: false, maxLength: 200 }, // 主播id
+  status: { type: String, required: false, maxLength: 64 }, // 状态0、开启1、关闭
 };
 
 const schema = new Schema(RoomSchema, { toJSON: { virtuals: true } });

+ 10 - 0
app/service/room.js

@@ -13,6 +13,16 @@ class RoomService extends CrudService {
     this.model = this.ctx.model.Room;
   }
 
+  async create(data) {
+    const { name } = data;
+    const room_ = await this.model.findOne({ name });
+    if (room_) {
+      throw new BusinessError('此房间已经存在,请重新输入');
+    }
+    const res = await this.model.create(data);
+    return res;
+  }
+
 }
 
 module.exports = RoomService;