Updating daysOfMonths array when the startDate of a monthly is updated in the API - Fixes #12041 (#12399)

* Updating daily daysOfMonth array when startDate is updated and adding integration tests to test this functionality

* Adding more test cases and adding semicolons to the end of lines

* Only updating the monthly repetition if the daily was already set to repeat on a day of the month

* fix(lint): whitespace

Co-authored-by: Laurel Thomson <laurel.beth.thomson@gmai.com>
Co-authored-by: Sabe Jones <sabrecat@gmail.com>
This commit is contained in:
Laurel Thomson
2020-07-31 02:16:55 -07:00
committed by GitHub
parent c4049608a8
commit 1f8e2d5677
2 changed files with 48 additions and 0 deletions

View File

@@ -681,6 +681,15 @@ api.updateTask = {
task.group.managerNotes = sanitizedObj.managerNotes;
}
// If the task was set to repeat monthly on a day of the month, and the start date was updated,
// the task will then need to be updated to repeat on the same day of the month as the new
// start date. For example, if the start date is updated to 7/2/2020, the daily should
// repeat on the 2nd day of the month. It's possible that a task can repeat monthly on a
// week of the month, in which case we won't update the repetition at all.
if (task.frequency === 'monthly' && task.daysOfMonth.length && task.startDate) {
task.daysOfMonth = [moment(task.startDate).date()];
}
setNextDue(task, user);
const savedTask = await task.save();