From a630623cf6e754e64ced6555ab7f5220b4a50990 Mon Sep 17 00:00:00 2001 From: xxeol Date: Wed, 19 Jan 2022 22:41:25 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20roomList=20=EB=B0=B0=EC=97=B4=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B2=84=EA=B7=B8=20=ED=94=BD=EC=8A=A4=20?= =?UTF-8?q?+=20profileImg=202=EA=B0=9C=EB=A7=8C=20=EB=9C=A8=EB=8A=94=20err?= =?UTF-8?q?or=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/api/routes/room/roomListGET.js | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/functions/api/routes/room/roomListGET.js b/functions/api/routes/room/roomListGET.js index 60a975b..524a656 100644 --- a/functions/api/routes/room/roomListGET.js +++ b/functions/api/routes/room/roomListGET.js @@ -37,11 +37,14 @@ module.exports = async (req, res) => { waitingRooms = _.sortBy(waitingRooms, 'createdAt').reverse(); // 최근에 생성된 대기방이 위로 let ongoingRooms = rawRooms.filter((rawRoom) => rawRoom.status === "ONGOING"); ongoingRooms = _.sortBy(ongoingRooms, 'startAt').reverse(); // 최근에 시작한 습관방이 위로 - console.log("waitingRooms", waitingRooms); - console.log("ongoingRooms", ongoingRooms); + // console.log("waitingRooms", waitingRooms); + // console.log("ongoingRooms", ongoingRooms); const waitingRoomIds = [...new Set(waitingRooms.filter(Boolean).map((room) => room.roomId))]; const ongoingRoomIds = [...new Set(ongoingRooms.filter(Boolean).map((room) => room.roomId))]; const roomIds = waitingRoomIds.concat(ongoingRoomIds); + console.log("waitingRoomIds", waitingRoomIds); + console.log("ongoingRoomIds", ongoingRoomIds); + console.log("roomIds", roomIds); let responseRoomIds = []; // 최초 요청이 아닐시 @@ -65,18 +68,20 @@ module.exports = async (req, res) => { return res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.GET_ROOM_LIST_SUCCESS, { "rooms": [] })); } - const roomInfo = await roomDB.getRoomsByIds(client, responseRoomIds); - + const rawRoomInfo = await roomDB.getRoomsByIds(client, responseRoomIds); + const roomInfo = rawRoomInfo.sort((a,b) => responseRoomIds.indexOf(a.roomId) - responseRoomIds.indexOf(b.roomId)); const today = dayjs(dayjs().add(9, 'hour').format('YYYY-M-D')); // roomIds 빈 배열일 때 처리 - const profiles = await roomDB.getUserProfilesByRoomIds(client, responseRoomIds, today); + const rawProfiles = await roomDB.getUserProfilesByRoomIds(client, responseRoomIds, today); + const profiles = rawProfiles.sort((a,b) => responseRoomIds.indexOf(a.roomId) - responseRoomIds.indexOf(b.roomId)); + console.log("profiles", profiles.map((o) => o.roomId)); - // console.log(profiles); let roomProfileImg = []; let roomMemberNum = []; let roomUserStatus = []; let roomDoneMemberNum = []; + responseRoomIds.map((roomId) => { const userStatus = profiles.filter(Boolean).filter((o) => { if (o.roomId === roomId && o.userId === user.userId) { @@ -102,8 +107,10 @@ module.exports = async (req, res) => { let profileImgs = profiles.filter(Boolean).filter((o) => o.roomId === roomId).map((o) => o.profileImg); roomMemberNum.push(profileImgs.length); if(profileImgs.length < 3) { - console.log("length", profileImgs.length); - for(let i=0; i<3 - profileImgs.length; i++) { + let i = 0; + const length = profileImgs.length; + + for(let i=0; i<3-length; i++) { profileImgs.push(null); } } @@ -114,15 +121,11 @@ module.exports = async (req, res) => { }); let rooms = []; - console.log("roomInfo", roomInfo); + // console.log("roomInfo", roomInfo); for (let i=0; i