Skip to content

Commit

Permalink
[FEAT] 오늘의 뮤멘트 조회 service 구현 #47
Browse files Browse the repository at this point in the history
  • Loading branch information
hujumee committed Jul 20, 2022
1 parent 853b7bf commit 9a27f65
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/interfaces/mument/TodayMumentResponseDto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MumentCardViewInterface } from './MumentCardViewInterface';
import { TodaySelectionInfo } from '../home/TodaySelectionInfo';

export interface TodayMumentResponseDto {
nowDate: Date;
todayMument: MumentCardViewInterface;
todayDate: string;
todayMument: TodaySelectionInfo;
}
35 changes: 34 additions & 1 deletion src/services/MumentService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import constant from '../modules/serviceReturnConstant';
import { tagBannerTitle } from '../modules/tagTitle';
import { tagRandomTitle } from '../modules/tagTitle';
Expand All @@ -17,9 +18,10 @@ import Music from '../models/Music';
import User from '../models/User';
import Like from '../models/Like';
import HomeCandidate from '../models/HomeCandidate';
import { HomeCandidateInfo } from '../interfaces/home/HomeCandidateInfo';
import TodaySelection from '../models/TodaySelection';
import { RandomMumentResponseDto } from '../interfaces/mument/RandomMumentResponeDto';
import { RandomMumentInterface } from '../interfaces/home/randomMumentInterface';
import { TodayMumentResponseDto } from '../interfaces/mument/TodayMumentResponseDto';

const createMument = async (userId: string, musicId: string, mumentCreateDto: MumentCreateDto): Promise<PostBaseResponseDto | null> => {
try {
Expand Down Expand Up @@ -521,6 +523,36 @@ const getRandomMument = async (): Promise<RandomMumentResponseDto | null> => {
}
};

// 오늘의 뮤멘트 조회
const getTodayMument = async (): Promise<TodayMumentResponseDto | number> => {
try {
dayjs.extend(utc);

// 리퀘스트 받아온 시간 판단 후 당일 자정으로 수정
const todayMidnight = new Date().setHours(0, 0, 0, 0);
const todayUtcDate = dayjs(todayMidnight).utc().format();
const todayDate = dayjs(todayMidnight).format('YYYY-MM-DD');

const todayMument = await TodaySelection.findOne({
displayDate: todayUtcDate,
});

if (!todayMument) {
return constant.NO_HOME_CONTENT;
}

const data: TodayMumentResponseDto = {
todayDate,
todayMument,
};

return data;
} catch (error) {
console.log(error);
throw error;
}
};

export default {
createMument,
updateMument,
Expand All @@ -531,4 +563,5 @@ export default {
createLike,
deleteLike,
getRandomMument,
getTodayMument,
};

0 comments on commit 9a27f65

Please sign in to comment.