From 7d259bf9c638b01bdeb33d44cd4c0f01232b27f9 Mon Sep 17 00:00:00 2001 From: youngkwon02 Date: Tue, 27 Sep 2022 14:57:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20LIFE=5FTIMELINE=5FREAD=5FSUCCESS?= =?UTF-8?q?=20=EC=84=9C=EB=B2=84=20=EC=9D=91=EB=8B=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/constants/responseMessage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/functions/constants/responseMessage.js b/functions/constants/responseMessage.js index 5171ff1..5ab35e7 100644 --- a/functions/constants/responseMessage.js +++ b/functions/constants/responseMessage.js @@ -69,6 +69,7 @@ module.exports = { // Life Timeline GET_LIFE_TIMELINE_SUCCESS: '생명 타임라인 조회 성공', + LIFE_TIMELINE_READ_SUCCESS: '생명 타임라인 읽음처리 완료', // Feed GET_FEED_SUCCES: '피드 조회 성공', From ea9a9844035b8bb865d3bbdeed38c9db13696ebd Mon Sep 17 00:00:00 2001 From: youngkwon02 Date: Tue, 27 Sep 2022 14:58:12 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=83=9D=EB=AA=85=20=ED=83=80?= =?UTF-8?q?=EC=9E=84=EB=9D=BC=EC=9D=B8=20=EC=9D=BD=EC=9D=8C=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20API=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/api/routes/room/index.js | 1 + .../api/routes/room/roomTimelineReadPATCH.js | 35 +++++++++++++++++++ functions/db/lifeTimeline.js | 15 ++++++++ 3 files changed, 51 insertions(+) create mode 100644 functions/api/routes/room/roomTimelineReadPATCH.js diff --git a/functions/api/routes/room/index.js b/functions/api/routes/room/index.js index 8e37623..cd97734 100644 --- a/functions/api/routes/room/index.js +++ b/functions/api/routes/room/index.js @@ -19,5 +19,6 @@ router.delete('/:roomId', checkUser, require('./roomDELETE')); router.delete('/:roomId/out', checkUser, require('./roomOutDELETE')); router.patch('/:roomId/read', checkUser, require('./roomReadPATCH')); router.get('/:roomId/timeline', checkUser, require('./roomTimelineGET')); +router.patch('/:roomId/timeline', checkUser, require('./roomTimelineReadPATCH')); module.exports = router; diff --git a/functions/api/routes/room/roomTimelineReadPATCH.js b/functions/api/routes/room/roomTimelineReadPATCH.js new file mode 100644 index 0000000..5ec27e2 --- /dev/null +++ b/functions/api/routes/room/roomTimelineReadPATCH.js @@ -0,0 +1,35 @@ +const functions = require('firebase-functions'); +const util = require('../../../lib/util'); +const statusCode = require('../../../constants/statusCode'); +const responseMessage = require('../../../constants/responseMessage'); +const db = require('../../../db/db'); +const { lifeTimelineDB } = require('../../../db'); + +/** + * @생명_타임라인_읽음_처리 + * @route PATCH /room/:roomId/timeline + * @body + * @error + */ + +module.exports = async (req, res) => { + const { roomId } = req.params; + const user = req.user; + + let client; + + try { + client = await db.connect(req); + + await lifeTimelineDB.readLifeTimeline(client, roomId, user.userId); + + res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.LIFE_TIMELINE_READ_SUCCESS)); + } catch (error) { + functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`); + console.log(error); + + res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); + } finally { + client.release(); + } +}; diff --git a/functions/db/lifeTimeline.js b/functions/db/lifeTimeline.js index 74f2072..39633ee 100644 --- a/functions/db/lifeTimeline.js +++ b/functions/db/lifeTimeline.js @@ -28,7 +28,22 @@ const getLifeTimeline = async (client, roomId, userId) => { return convertSnakeToCamel.keysToCamel(rows); }; +const readLifeTimeline = async (client, roomId, userId) => { + const { rows } = await client.query( + ` + UPDATE spark.life_timeline + SET is_read = TRUE + WHERE room_id = $1 + AND receiver_id = $2 + RETURNING * + `, + [roomId, userId], + ); + return convertSnakeToCamel.keysToCamel(rows); +}; + module.exports = { addLifeTimeline, getLifeTimeline, + readLifeTimeline, }; From 5922976baded1572c548c04e50038c64acbef59e Mon Sep 17 00:00:00 2001 From: youngkwon02 Date: Tue, 27 Sep 2022 14:59:30 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EC=83=9D=EB=AA=85=20=ED=83=80?= =?UTF-8?q?=EC=9E=84=EB=9D=BC=EC=9D=B8=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=EC=9C=BC=EB=A1=9C=20=EC=9D=BD=EC=9D=8C?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/api/routes/room/index.js | 1 - functions/api/routes/room/roomTimelineGET.js | 2 ++ .../api/routes/room/roomTimelineReadPATCH.js | 35 ------------------- 3 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 functions/api/routes/room/roomTimelineReadPATCH.js diff --git a/functions/api/routes/room/index.js b/functions/api/routes/room/index.js index cd97734..8e37623 100644 --- a/functions/api/routes/room/index.js +++ b/functions/api/routes/room/index.js @@ -19,6 +19,5 @@ router.delete('/:roomId', checkUser, require('./roomDELETE')); router.delete('/:roomId/out', checkUser, require('./roomOutDELETE')); router.patch('/:roomId/read', checkUser, require('./roomReadPATCH')); router.get('/:roomId/timeline', checkUser, require('./roomTimelineGET')); -router.patch('/:roomId/timeline', checkUser, require('./roomTimelineReadPATCH')); module.exports = router; diff --git a/functions/api/routes/room/roomTimelineGET.js b/functions/api/routes/room/roomTimelineGET.js index ffc6bf8..73bef05 100644 --- a/functions/api/routes/room/roomTimelineGET.js +++ b/functions/api/routes/room/roomTimelineGET.js @@ -69,6 +69,8 @@ module.exports = async (req, res) => { return timeline; }); + await lifeTimelineDB.readLifeTimeline(client, roomId, user.userId); + return res.status(statusCode.OK).send( util.success(statusCode.OK, responseMessage.GET_LIFE_TIMELINE_SUCCESS, { timelines, diff --git a/functions/api/routes/room/roomTimelineReadPATCH.js b/functions/api/routes/room/roomTimelineReadPATCH.js deleted file mode 100644 index 5ec27e2..0000000 --- a/functions/api/routes/room/roomTimelineReadPATCH.js +++ /dev/null @@ -1,35 +0,0 @@ -const functions = require('firebase-functions'); -const util = require('../../../lib/util'); -const statusCode = require('../../../constants/statusCode'); -const responseMessage = require('../../../constants/responseMessage'); -const db = require('../../../db/db'); -const { lifeTimelineDB } = require('../../../db'); - -/** - * @생명_타임라인_읽음_처리 - * @route PATCH /room/:roomId/timeline - * @body - * @error - */ - -module.exports = async (req, res) => { - const { roomId } = req.params; - const user = req.user; - - let client; - - try { - client = await db.connect(req); - - await lifeTimelineDB.readLifeTimeline(client, roomId, user.userId); - - res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.LIFE_TIMELINE_READ_SUCCESS)); - } catch (error) { - functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`); - console.log(error); - - res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); - } finally { - client.release(); - } -};