Skip to content

Commit

Permalink
Merge pull request #96 from TeamSparker/feature/#62
Browse files Browse the repository at this point in the history
[FEAT] 최초 인증시 entry에 thumbnail 생성
  • Loading branch information
xxeol2 authored Jan 18, 2022
2 parents cbdd2b5 + 999209e commit 59858db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions functions/api/routes/room/roomListGET.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = async (req, res) => {
const rawRooms = await roomDB.getRoomsByUserId(client, user.userId);

let waitingRooms = rawRooms.filter((rawRoom) => rawRoom.status === "NONE");
waitingRooms = _.sortBy(waitingRooms, 'createdAt').reverse();
waitingRooms = _.sortBy(waitingRooms, 'createdAt').reverse(); // 최근에 생성된 대기방이 위로
let ongoingRooms = rawRooms.filter((rawRoom) => rawRoom.status === "ONGOING");
ongoingRooms = _.sortBy(ongoingRooms, 'startAt').reverse();
ongoingRooms = _.sortBy(ongoingRooms, 'startAt').reverse(); // 최근에 시작한 습관방이 위로
console.log("waitingRooms", waitingRooms);
console.log("ongoingRooms", ongoingRooms);
const waitingRoomIds = [...new Set(waitingRooms.filter(Boolean).map((room) => room.roomId))];
Expand Down
4 changes: 4 additions & 0 deletions functions/api/routes/room/roomRecordPOST.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module.exports = async (req, res) => {
}

const uploadedRecord = await recordDB.uploadRecord(client, record.recordId, certifyingImg[0], timerRecord);
if (!entry.thumbnail) {
await roomDB.updateThumbnail(client, entry.entryId, certifyingImg[0]);
// @TODO 첫번째 습관 인증 축하 알림
}

const data = {
userId: user.userId,
Expand Down
13 changes: 13 additions & 0 deletions functions/db/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ const updateLife = async(client, failCount, roomIds) => {
return convertSnakeToCamel.keysToCamel(rows);
}

const updateThumbnail = async(client, entryId, img) => {
const { rows } = await client.query(
`
UPDATE spark.entry e
SET thumbnail = $2
WHERE entry_id = $1
`,
[entryId, img]
);
return convertSnakeToCamel.keysToCamel(rows[0]);
}

module.exports = {
addRoom,
isCodeUnique,
Expand All @@ -427,4 +439,5 @@ module.exports = {
updateLife,
getFailRecords,
getEntriesByRoomIds,
updateThumbnail
};

0 comments on commit 59858db

Please sign in to comment.