From aceb7052aabc453274d6fdd314740d339ec84ad9 Mon Sep 17 00:00:00 2001 From: Youjung Heo Date: Thu, 21 Jul 2022 23:46:24 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EB=B0=B0=EB=84=88=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20service=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= =?UTF-8?q?=20#49?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/MumentService.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/services/MumentService.ts b/src/services/MumentService.ts index 8fba694..f405cf9 100644 --- a/src/services/MumentService.ts +++ b/src/services/MumentService.ts @@ -22,6 +22,9 @@ import TodaySelection from '../models/TodaySelection'; import { RandomMumentResponseDto } from '../interfaces/mument/RandomMumentResponeDto'; import { RandomMumentInterface } from '../interfaces/home/randomMumentInterface'; import { TodayMumentResponseDto } from '../interfaces/mument/TodayMumentResponseDto'; +import { TodayBannerResponseDto } from '../interfaces/mument/TodayBannerResponseDto'; +import BannerSelection from '../models/BannerSelection'; +import { BannerSelectionInfo } from '../interfaces/home/BannerSelectionInfo'; const createMument = async (userId: string, musicId: string, mumentCreateDto: MumentCreateDto): Promise => { try { @@ -553,6 +556,34 @@ const getTodayMument = async (): Promise => { } }; +// 배너 조회 +const getBanner = async (): Promise => { + try { + dayjs.extend(utc); + + // 날짜 비교를 위해 이번주 월요일 자정 날짜 받아오기 + const mondayMidnight = dayjs(new Date().setHours(0, 0, 0, 0)).day(1).utc().format(); + + const todayDate = dayjs().format('YYYY-MM-DD'); + + const bannerList: BannerSelectionInfo[] = await BannerSelection.find({ + displayDate: mondayMidnight, + }); + + if (bannerList.length === 0) return constant.NO_HOME_CONTENT; + + const data: TodayBannerResponseDto = { + todayDate, + bannerList, + }; + + return data; + } catch (error) { + console.log(error); + throw error; + } +}; + export default { createMument, updateMument, @@ -564,4 +595,5 @@ export default { deleteLike, getRandomMument, getTodayMument, + getBanner, };