Skip to content
Snippets Groups Projects
Commit ecbb6dbe authored by 조대희's avatar 조대희
Browse files

fix: 스케줄 수정 & 만료일 구하기 수정 (#6)

parent be3b1ba9
No related branches found
No related tags found
2 merge requests!31Develop,!7[#6] Schedule 컨트롤러, 라우터, 로직 개발
......@@ -54,13 +54,16 @@ class scheduleService {
/**
* 유동 스케줄 만료일 구하기
*/
getNextMonday() {
const date = new Date();
getNextMonday(startTime) {
const date = new Date(startTime);
const day = date.getDay();
const daysUntilNextMonday = (8 - day) % 7;
date.setDate(date.getDate() + daysUntilNextMonday);
date.setHours(0, 0, 0, 0);
return date;
const daysUntilNextMonday = (7 - day + 1) % 7;
const nextMonday = new Date(date);
nextMonday.setDate(date.getDate() + daysUntilNextMonday);
nextMonday.setHours(0, 0, 0, 0); // 자정으로 설정
return nextMonday;
}
/**
......@@ -81,7 +84,7 @@ class scheduleService {
start_time,
end_time,
is_fixed,
expiry_date: is_fixed ? null : this.getNextMonday()
expiry_date: is_fixed ? null : this.getNextMonday(start_time)
};
return Schedule.create(scheduleData, { transaction });
......@@ -114,8 +117,15 @@ class scheduleService {
throw new Error('Schedule overlaps with existing schedule');
}
delete updateData.is_fixed;
return schedule.update(updateData, { transaction });
const is_fixed = schedule.is_fixed;
const updatedData = {
...updateData,
expiry_date: is_fixed ? null : this.getNextMonday(updateData.start_time),
updatedAt: new Date()
};
delete updatedData.is_fixed;
return schedule.update(updatedData, { transaction });
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment