diff --git a/functions/db/lifeTimeline.js b/functions/db/lifeTimeline.js index 39633ee..2c117a0 100644 --- a/functions/db/lifeTimeline.js +++ b/functions/db/lifeTimeline.js @@ -6,7 +6,7 @@ const addLifeTimeline = async (client, timelines) => { const { rows } = await client.query( ` INSERT INTO spark.life_timeline - (receiver_id, room_id, is_decrease, profile_1, profile_2) + (receiver_id, room_id, is_decrease, decrease_count, profile_1, profile_2) VALUES ${timelines.join()} RETURNING * diff --git a/functions/scheduler/funcs.js b/functions/scheduler/funcs.js index bc2c79e..db8d413 100644 --- a/functions/scheduler/funcs.js +++ b/functions/scheduler/funcs.js @@ -84,19 +84,21 @@ const checkLife = async () => { decreaseMessageUsers = await roomDB.getAllUsersByIds(client, lifeDeductionRoomIds); } let failProfiles = {}; // 인증 안한 사용자 프로필 사진, key: roomId, value: profile 배열 + let decreaseCount = {}; // 인증 안한 사용자 수, key: roomId, value: decreaseCount let decreaseMessage = []; for (let i = 0; i < decreaseMessageUsers.length; i++) { const { userId, roomId } = decreaseMessageUsers[i]; if (!Object.keys(failProfiles).includes(roomId)) { let profiles = await roomDB.getFailProfiles(client, roomId); profiles = profiles.map((p) => p.profile).sort(() => Math.random() - 0.5); + decreaseCount[roomId] = profiles.length; while (profiles.length < 2) { profiles.push(null); } failProfiles[roomId] = profiles; } - decreaseMessage.push(`('${userId}', '${roomId}', true, '${failProfiles[roomId][0]}', '${failProfiles[roomId][1]}')`); + decreaseMessage.push(`('${userId}', '${roomId}', true, ${decreaseCount[roomId]}, '${failProfiles[roomId][0]}', '${failProfiles[roomId][1]}')`); } // 생명 감소시 Time Line Insert