Skip to content

Commit

Permalink
refactor: msw 모킹 로직에서의 변수명 통일
Browse files Browse the repository at this point in the history
- ~~DateFormat → ~~Date
  • Loading branch information
wzrabbit committed Dec 25, 2023
1 parent 2004860 commit 2471116
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions frontend/src/mocks/handlers/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ let mySchedules = [...myScheduleData];
export const calendarHandlers = [
//통합캘린더 일정 기간 조회
rest.get(`/api/my-calendar/schedules`, (req, res, ctx) => {
const startDateFormat = req.url.searchParams.get('startDate');
const endDateFormat = req.url.searchParams.get('endDate');
const startDate = req.url.searchParams.get('startDate');
const endDate = req.url.searchParams.get('endDate');

if (!startDateFormat || !endDateFormat) {
if (!startDate || !endDate) {
return res(ctx.status(400));
}

const searchedMySchedules = mySchedules.filter(
({ startDateTime, endDateTime }) => {
const isScheduleInRange =
startDateFormat <=
startDate <=
generateYYYYMMDDWithoutHyphens(new Date(startDateTime)) ||
endDateFormat >=
generateYYYYMMDDWithoutHyphens(new Date(endDateTime));
endDate >= generateYYYYMMDDWithoutHyphens(new Date(endDateTime));

return isScheduleInRange;
},
Expand All @@ -44,26 +43,25 @@ export const calendarHandlers = [
`/api/team-place/:teamPlaceId/calendar/schedules`,
(req, res, ctx) => {
const teamPlaceId = Number(req.params.teamPlaceId);
const startDateFormat = req.url.searchParams.get('startDate');
const endDateFormat = req.url.searchParams.get('endDate');
const startDate = req.url.searchParams.get('startDate');
const endDate = req.url.searchParams.get('endDate');

const index = teamPlaces.findIndex(
(teamPlace) => teamPlace.id === teamPlaceId,
);

if (index === -1) return res(ctx.status(403));

if (!startDateFormat || !endDateFormat) {
if (!startDate || !endDate) {
return res(ctx.status(400));
}

const searchedSchedules = schedules.filter(
({ startDateTime, endDateTime }) => {
const isScheduleInRange =
startDateFormat <=
startDate <=
generateYYYYMMDDWithoutHyphens(new Date(startDateTime)) ||
endDateFormat >=
generateYYYYMMDDWithoutHyphens(new Date(endDateTime));
endDate >= generateYYYYMMDDWithoutHyphens(new Date(endDateTime));

return isScheduleInRange;
},
Expand Down

0 comments on commit 2471116

Please sign in to comment.