Skip to content
Snippets Groups Projects
Commit a43bd19a authored by DongJae Oh's avatar DongJae Oh
Browse files

feat: Fix api

parent 071cfb94
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,12 @@ class ChatController extends BaseController { ...@@ -19,6 +19,12 @@ class ChatController extends BaseController {
return await this.chatService.getRoomId(myUserId, userIds, roomName); return await this.chatService.getRoomId(myUserId, userIds, roomName);
} }
async getRoomInfo(req, res) {
const myUserId = req.user.id;
const roomId = req.params.roomId;
return await this.chatService.getRoomInfo(myUserId, roomId);
}
async getMessages(req, res) { async getMessages(req, res) {
const roomId = req.params.roomId; const roomId = req.params.roomId;
const startId = req.query.startId || 0; const startId = req.query.startId || 0;
......
...@@ -26,6 +26,12 @@ chatRouter.post( ...@@ -26,6 +26,12 @@ chatRouter.post(
chatController.getRoomId chatController.getRoomId
); );
chatRouter.get(
"/roomInfo/:roomId",
authController.checkUserSession,
chatController.getRoomInfo
);
chatRouter.get( chatRouter.get(
"/roomList", "/roomList",
authController.checkUserSession, authController.checkUserSession,
......
...@@ -7,6 +7,16 @@ class ChatService { ...@@ -7,6 +7,16 @@ class ChatService {
this.roomRepository = roomRepository; this.roomRepository = roomRepository;
this.userRepository = userRepository; this.userRepository = userRepository;
} }
async getRoomInfo(userId, roomId) {
const allRooms = await this.getRoomList(userId);
for (let room of allRooms) {
if (room.roomId == roomId) {
return { roomName: room.roomName, roomSize: room.users.length };
}
}
return { roomName: "", roomSize: 0 };
}
async getRoomList(userId) { async getRoomList(userId) {
let roomList = []; let roomList = [];
......
...@@ -124,11 +124,10 @@ class RoomRepository { ...@@ -124,11 +124,10 @@ class RoomRepository {
reject(error); reject(error);
} else { } else {
if (result.length < 1) { if (result.length < 1) {
resolve(null) resolve(null);
} else { } else {
resolve(result[0].room_id); resolve(result[0].room_id);
} }
} }
} }
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment