From fbe7d1e2975e3e769affa15fa804e4c4cad87ae0 Mon Sep 17 00:00:00 2001 From: Ji Seungmin Date: Fri, 11 Aug 2023 23:32:21 +0900 Subject: [PATCH] =?UTF-8?q?[feat]:=20=EC=84=B1=EA=B3=B5=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EC=97=90=20roomId=20=EB=B0=98=ED=99=98=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/createRoom.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/routes/createRoom.js b/routes/createRoom.js index 5fc5b8e..19dc24b 100644 --- a/routes/createRoom.js +++ b/routes/createRoom.js @@ -41,13 +41,18 @@ router.post('/', async (req, res) => { if(chatrooms){ if(chatrooms.participants.includes(me)){ - // 채팅방에 이미 참여자(me)가 있으므로 오류 발생 - throw new Error("Chatroom already exists!"); + + res.json({ roomId: chatrooms.roomId }); + return + } else { // 채팅방에 참여자(me) 추가 chatrooms.participants.push(me); chatrooms.buyer_enter = new Date(); await chatrooms.save(); + + res.json({ roomId: chatrooms.roomId }); + return } } else { // 채팅방이 존재하지 않으므로 생성 @@ -60,10 +65,11 @@ router.post('/', async (req, res) => { seller_enter: new Date() }); await newChatroom.save(); + + res.json({ roomId: newChatroom.roomId }); + return } - res.send(response.data); - } catch (error) { if (error.message === "Chatroom already exists!") { res.status(400).json({ message: "채팅방이 이미 존재합니다", code: 60000 });