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, +};