Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

fix : 날짜 수정 #191

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/journey/journey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Injectable,
NotFoundException,
} from '@nestjs/common';
import { addDays, isAfter } from 'date-fns';
import { addDays, isAfter, isEqual } from 'date-fns';
import { JourneyEntity } from './model/journey.entity';
import { errResponse, response } from 'src/response/response';
import { BaseResponse } from 'src/response/response.status';
Expand Down Expand Up @@ -46,20 +46,24 @@ export class JourneyService {
let currentDate = startDate;
const schedules = [];

// endDate가 startDate 이후인지 확인
if (isAfter(endDate, startDate)) {
while (currentDate <= endDate) {
const schedule = await ScheduleEntity.createSchedule(
journey,
currentDate,
);
schedules.push(schedule);
currentDate = addDays(currentDate, 1); // 다음 날짜로 이동
}
// startDate와 endDate가 같은 경우 하나의 schedule 생성
if (isEqual(startDate, endDate)) {
const schedule = await ScheduleEntity.createSchedule(journey, startDate);
schedules.push(schedule);
} else {
throw new Error('endDate는 startDate보다 이후여야 합니다.');
let currentDate = startDate;
// endDate가 startDate 이후인지 확인하여 일정 배너 생성
if (isAfter(endDate, startDate)) {
while (currentDate <= endDate) {
const schedule = await ScheduleEntity.createSchedule(
journey,
currentDate,
);
schedules.push(schedule);
currentDate = addDays(currentDate, 1); // 다음 날짜로 이동
}
}
}

return schedules;
}

Expand Down