From 281202e20e04e9c0c8e76b6d2a524d02feb50986 Mon Sep 17 00:00:00 2001 From: youngkwon02 Date: Sat, 1 Oct 2022 17:03:13 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=95=8C=EB=A6=BC=20=EC=84=BC?= =?UTF-8?q?=ED=84=B0=20=EB=B0=8F=20=EC=83=9D=EB=AA=85=20=ED=83=80=EC=9E=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=EC=97=90=20passedDayToStr=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/api/routes/notice/active/activeGET.js | 3 ++- .../api/routes/notice/service/serviceGET.js | 3 ++- functions/api/routes/room/roomTimelineGET.js | 3 ++- functions/lib/passedDayToStr.js | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 functions/lib/passedDayToStr.js diff --git a/functions/api/routes/notice/active/activeGET.js b/functions/api/routes/notice/active/activeGET.js index c96af63..b7adffa 100644 --- a/functions/api/routes/notice/active/activeGET.js +++ b/functions/api/routes/notice/active/activeGET.js @@ -6,6 +6,7 @@ const responseMessage = require('../../../../constants/responseMessage'); const db = require('../../../../db/db'); const slackAPI = require('../../../../middlewares/slackAPI'); const { noticeDB } = require('../../../../db'); +const { passedDayToStr } = require('../../../../lib/passedDayToStr'); /** * @활동_알림_조회 @@ -45,7 +46,7 @@ module.exports = async (req, res) => { notice['noticeContent'] = a.content; notice['noticeImg'] = a.thumbnail; notice['isThumbProfile'] = a.isThumbProfile; - notice['day'] = passedDay > 0 ? `${passedDay}일전` : `오늘`; + notice['day'] = passedDayToStr(passedDay); notice['isNew'] = !a.isRead; return notice; }); diff --git a/functions/api/routes/notice/service/serviceGET.js b/functions/api/routes/notice/service/serviceGET.js index 531816e..992b0af 100644 --- a/functions/api/routes/notice/service/serviceGET.js +++ b/functions/api/routes/notice/service/serviceGET.js @@ -6,6 +6,7 @@ const responseMessage = require('../../../../constants/responseMessage'); const db = require('../../../../db/db'); const slackAPI = require('../../../../middlewares/slackAPI'); const { noticeDB } = require('../../../../db'); +const { passedDayToStr } = require('../../../../lib/passedDayToStr'); /** * @서비스_알림_조회 @@ -43,7 +44,7 @@ module.exports = async (req, res) => { notice['noticeId'] = s.notificationId; notice['noticeTitle'] = s.title; notice['noticeContent'] = s.content; - notice['day'] = passedDay > 0 ? `${passedDay}일전` : `오늘`; + notice['day'] = passedDayToStr(passedDay); notice['isNew'] = !s.isRead; return notice; }); diff --git a/functions/api/routes/room/roomTimelineGET.js b/functions/api/routes/room/roomTimelineGET.js index 875cd76..4eb1cb0 100644 --- a/functions/api/routes/room/roomTimelineGET.js +++ b/functions/api/routes/room/roomTimelineGET.js @@ -7,6 +7,7 @@ const { roomDB, lifeTimelineDB } = require('../../../db'); const timelineMessage = require('../../../constants/lifeTimelineMessage'); const slackAPI = require('../../../middlewares/slackAPI'); const dayjs = require('dayjs'); +const { passedDayToStr } = require('../../../lib/passedDayToStr'); /** * @습관방_생명_타임라인_조회 @@ -63,7 +64,7 @@ module.exports = async (req, res) => { timeline['title'] = title; timeline['content'] = content; timeline['profiles'] = profiles; - timeline['day'] = passedDay > 0 ? `${passedDay}일전` : `오늘`; + timeline['day'] = passedDayToStr(passedDay); timeline['isNew'] = !t.isRead; return timeline; diff --git a/functions/lib/passedDayToStr.js b/functions/lib/passedDayToStr.js new file mode 100644 index 0000000..c9fea25 --- /dev/null +++ b/functions/lib/passedDayToStr.js @@ -0,0 +1,17 @@ +const passedDayToStr = (passedDay) => { + if (passedDay === 0) { + return '오늘'; + } + + if (passedDay < 7) { + return `${passedDay}일 전`; + } + + if (passedDay < 30) { + return `${Math.floor(passedDay / 7)}주 전`; + } +}; + +module.exports = { + passedDayToStr, +};