Skip to content

Refactor vacation scheduling logic in WorkdayService to streamline input validation and improve time resolution#46

Merged
jeyongsong merged 1 commit intomainfrom
fix-allow-vacation-on-any-day
Apr 5, 2026
Merged

Refactor vacation scheduling logic in WorkdayService to streamline input validation and improve time resolution#46
jeyongsong merged 1 commit intomainfrom
fix-allow-vacation-on-any-day

Conversation

@jeyongsong
Copy link
Copy Markdown
Member

This pull request refactors how vacation schedule times are resolved in the WorkdayService. The main change is the removal of the validateVacationInput method and integrating its logic directly into the resolveVacationTimes function, streamlining the handling of vacation workdays and reducing redundant validation.

Vacation schedule handling:

  • Removed the validateVacationInput method, eliminating a separate validation step for vacation inputs and simplifying the code path for vacation scheduling.
  • Updated the resolveVacationTimes method to take date, req, and savedSchedule as parameters, and incorporated logic to resolve the correct clock-in and clock-out times for vacation days, including using existing schedules if available. [1] [2] [3]

These changes make the vacation scheduling logic more concise and easier to maintain.

Copilot AI review requested due to automatic review settings April 5, 2026 09:28
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Test Results

47 tests   47 ✅  0s ⏱️
 6 suites   0 💤
 6 files     0 ❌

Results for commit bae0caf.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors vacation schedule time resolution in WorkdayService by removing the dedicated validateVacationInput method and folding parts of that logic into resolveVacationTimes, with the goal of simplifying the vacation upsert flow.

Changes:

  • Removed validateVacationInput and updated the VACATION upsert path to call the new resolveVacationTimes(date, req, existingSchedule, policy).
  • Updated resolveVacationTimes to optionally derive clock-in/clock-out from an existing saved schedule before falling back to policy defaults.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +327 to 332
val schedule = resolveSchedule(savedSchedule, policy, date)
if (schedule.clockIn != null && schedule.clockOut != null) {
return schedule.clockIn to schedule.clockOut
}

return policy.clockInTime to policy.clockOutTime
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveVacationTimes no longer enforces the validation that previously existed in validateVacationInput. With the current logic, if the request omits times, the method will (a) use savedSchedule times even when the saved schedule is a non-default/custom WORK schedule, and (b) fall back to policy times even when resolveSchedule(...) resolves to NONE (e.g., a non-workday). This is a concrete behavior change from the removed guard that threw BadRequestException(ErrorCode.INVALID_WORKDAY_INPUT) when the date was not the default work schedule. If that constraint is still required, reintroduce the equivalent check here (e.g., only allow implicit vacation times when the resolved schedule is default WORK with policy times, or when the existing saved schedule is already VACATION).

Suggested change
val schedule = resolveSchedule(savedSchedule, policy, date)
if (schedule.clockIn != null && schedule.clockOut != null) {
return schedule.clockIn to schedule.clockOut
}
return policy.clockInTime to policy.clockOutTime
if (
savedSchedule?.type == DailyWorkScheduleType.VACATION &&
savedSchedule.clockInTime != null &&
savedSchedule.clockOutTime != null
) {
return savedSchedule.clockInTime to savedSchedule.clockOutTime
}
val schedule = resolveSchedule(savedSchedule, policy, date)
if (
savedSchedule == null &&
schedule.type == DailyWorkScheduleType.WORK &&
schedule.clockIn != null &&
schedule.clockOut != null
) {
return schedule.clockIn to schedule.clockOut
}
throw BadRequestException(ErrorCode.INVALID_WORKDAY_INPUT)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

@jeyongsong jeyongsong Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior change is intentional.
We explicitly removed validateVacationInput so VACATION can be upserted even when the date is not a default workday or when a custom saved schedule already exists.
Time resolution now follows this order: request values, existing/resolved schedule values, then policy default times.

@jeyongsong jeyongsong merged commit 7a5a11e into main Apr 5, 2026
7 checks passed
@jeyongsong jeyongsong deleted the fix-allow-vacation-on-any-day branch April 5, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants