fix(task): make sure daysOfMonth update is only applied to dailies

This commit is contained in:
Matteo Pagliazzi
2020-08-10 19:08:36 +02:00
parent 747c4ffbad
commit 535aa860f1
2 changed files with 11 additions and 6 deletions

View File

@@ -681,12 +681,17 @@ api.updateTask = {
task.group.managerNotes = sanitizedObj.managerNotes; 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, // If the daily task was set to repeat monthly on a day of the month, and the start date was
// the task will then need to be updated to repeat on the same day of the month as the new // updated, the task will then need to be updated to repeat on the same day of the month as the
// start date. For example, if the start date is updated to 7/2/2020, the daily should // 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 // 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. // week of the month, in which case we won't update the repetition at all.
if (task.frequency === 'monthly' && task.daysOfMonth.length && task.startDate) { if (
task.type === 'daily'
&& task.frequency === 'monthly'
&& task.daysOfMonth.length
&& task.startDate
) {
task.daysOfMonth = [moment(task.startDate).date()]; task.daysOfMonth = [moment(task.startDate).date()];
} }

View File

@@ -363,9 +363,9 @@ export const DailySchema = new Schema(_.defaults({
}, },
streak: { $type: Number, default: 0 }, streak: { $type: Number, default: 0 },
// Days of the month that the daily should repeat on // Days of the month that the daily should repeat on
daysOfMonth: { $type: [Number], default: [] }, daysOfMonth: { $type: [Number], default: () => [] },
// Weeks of the month that the daily should repeat on // Weeks of the month that the daily should repeat on
weeksOfMonth: { $type: [Number], default: [] }, weeksOfMonth: { $type: [Number], default: () => [] },
isDue: { $type: Boolean }, isDue: { $type: Boolean },
nextDue: [{ $type: String }], nextDue: [{ $type: String }],
yesterDaily: { $type: Boolean, default: true, required: true }, yesterDaily: { $type: Boolean, default: true, required: true },