From e4feb90758d468d5ab9d785243a5c37002ca552f Mon Sep 17 00:00:00 2001 From: Ji Seungmin Date: Wed, 16 Aug 2023 15:04:23 +0900 Subject: [PATCH] =?UTF-8?q?[feat]:=20=EC=B1=84=ED=8C=85=EB=B0=A9=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=EA=B8=B0=EB=8A=A5=20=EB=B0=8F=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20url=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/finAllRoom.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes/finAllRoom.js b/routes/finAllRoom.js index 6602a2a..c34431e 100644 --- a/routes/finAllRoom.js +++ b/routes/finAllRoom.js @@ -34,8 +34,10 @@ router.get('/', async (req, res) => { .then(async (chatrooms) => { //Promise.all과 map을 통해 각 chatroom에 대해 반환값을 가져오는 것을 병렬로 실행 const reducedChatrooms = await Promise.all(chatrooms.map(async (chatroom) => { - // Define other + let other = (chatroom.buyer == me) ? chatroom.seller : chatroom.buyer; + let otherImageResponse = await axios.get(resource_url + `/image?otherId=${other}`); + let otherImage = otherImageResponse.data.otherImage // Fetch the last chat let lastChat = await chat.findOne({ roomId: chatroom.roomId }).sort({ time: -1 }); @@ -47,11 +49,14 @@ router.get('/', async (req, res) => { seller: chatroom.seller, username: me, other: other, + otherImage: otherImage, message: lastChat ? lastChat.content : null, time: lastChat ? lastChat.time : null, remain: 10 } })); + + reducedChatrooms.sort((a, b) => (b.time || 0) - (a.time || 0)); res.json(reducedChatrooms); // 조회된 chatrooms을 응답으로 전송 }) .catch((err) => {