Skip to content

Commit

Permalink
[feat]: 성공 응답에 roomId 반환값을 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Gseungmin committed Aug 11, 2023
1 parent 9c99945 commit fbe7d1e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions routes/createRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// 채팅방이 존재하지 않으므로 생성
Expand All @@ -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 });
Expand Down

0 comments on commit fbe7d1e

Please sign in to comment.