Skip to content

Commit

Permalink
[FEAT] 배너 조회 service 구현 완료 #49
Browse files Browse the repository at this point in the history
  • Loading branch information
hujumee committed Jul 21, 2022
1 parent 4165126 commit aceb705
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/services/MumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostBaseResponseDto | null> => {
try {
Expand Down Expand Up @@ -553,6 +556,34 @@ const getTodayMument = async (): Promise<TodayMumentResponseDto | number> => {
}
};

// 배너 조회
const getBanner = async (): Promise<TodayBannerResponseDto | number> => {
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,
Expand All @@ -564,4 +595,5 @@ export default {
deleteLike,
getRandomMument,
getTodayMument,
getBanner,
};

0 comments on commit aceb705

Please sign in to comment.