From 73c706e387aa23909a7252a66e976dbfcc7075f8 Mon Sep 17 00:00:00 2001 From: hoeeeeeh Date: Mon, 2 Dec 2024 10:28:12 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20init=20data=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/chatServer/src/room/room.repository.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/chatServer/src/room/room.repository.ts b/backend/chatServer/src/room/room.repository.ts index 3289d2d0..5549272a 100644 --- a/backend/chatServer/src/room/room.repository.ts +++ b/backend/chatServer/src/room/room.repository.ts @@ -39,19 +39,24 @@ export class RoomRepository { private async lindex(key: string, index: number){ const result = await this.redisClient.lindex(key, index); - if(result) return JSON.parse(result) as T; - return undefined; + if(!result) return undefined; + + const l = typeof result === 'string' ? result : JSON.parse(result); + return l as T; } private async lrange(key: string, start: number, end: number){ const result = await this.redisClient.lrange(key, start, end); - return result as T; + if(!result) return undefined; + const arrayT = result.map((r) => typeof r === 'string' ? r : JSON.parse(r)); + return arrayT as T; } private async getData(key: string) { const result = await this.redisClient.get(key); - if(result) return typeof result === 'string' ? result as T : JSON.parse(result) as T; - return undefined; + if(!result) return undefined; + const data = result === 'string' ? result : JSON.parse(result); + return data as T; } async isRoomExisted(roomId: string) {