fix: Corriger la disparition des créneaux lors d'un déplacement inter-jour
Lors d'un drag & drop d'un créneau vers un autre jour de la semaine, le nouveau créneau devenait invisible car recurrenceStart était fixé à la date d'occurrence (le jour source). Si le jour cible tombait avant cette date dans la semaine, isActiveOnDate retournait false. recurrenceStart est maintenant fixé au lundi de la semaine d'occurrence, ce qui garantit la visibilité du créneau dès la semaine du déplacement.
This commit is contained in:
@@ -117,7 +117,12 @@ final readonly class UpdateRecurringSlotHandler
|
||||
$slot->terminerRecurrenceLe($dayBefore, $now);
|
||||
$this->slotRepository->save($slot);
|
||||
|
||||
// Create new slot starting from the occurrence date
|
||||
// Use the Monday of the occurrence week as recurrenceStart so the new slot
|
||||
// is visible in the current week even when moved to an earlier day-of-week.
|
||||
$dayN = (int) $occurrenceDate->format('N');
|
||||
$weekMonday = $occurrenceDate->modify('-' . ($dayN - 1) . ' days');
|
||||
|
||||
// Create new slot starting from the Monday of the occurrence week
|
||||
$newSlot = ScheduleSlot::creer(
|
||||
tenantId: $tenantId,
|
||||
classId: ClassId::fromString($command->classId),
|
||||
@@ -128,7 +133,7 @@ final readonly class UpdateRecurringSlotHandler
|
||||
room: $command->room,
|
||||
isRecurring: true,
|
||||
now: $now,
|
||||
recurrenceStart: $occurrenceDate,
|
||||
recurrenceStart: $weekMonday,
|
||||
recurrenceEnd: $originalRecurrenceEnd,
|
||||
);
|
||||
|
||||
|
||||
@@ -119,6 +119,41 @@ final class UpdateRecurringSlotHandlerTest extends TestCase
|
||||
self::assertTrue($result['newSlot']->teacherId->equals(UserId::fromString(self::NEW_TEACHER_ID)));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function allFutureCrossDayMoveSetsRecurrenceStartToWeekMonday(): void
|
||||
{
|
||||
// Wednesday slot — moving it to Monday
|
||||
$slot = $this->createAndSaveSlot(
|
||||
dayOfWeek: DayOfWeek::WEDNESDAY,
|
||||
recurrenceStart: new DateTimeImmutable('2026-09-01'),
|
||||
recurrenceEnd: new DateTimeImmutable('2027-07-04'),
|
||||
);
|
||||
|
||||
$command = new UpdateRecurringSlotCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
slotId: (string) $slot->id,
|
||||
occurrenceDate: '2026-10-14', // Wednesday
|
||||
scope: 'all_future',
|
||||
classId: self::CLASS_ID,
|
||||
subjectId: self::SUBJECT_ID,
|
||||
teacherId: self::TEACHER_ID,
|
||||
dayOfWeek: DayOfWeek::MONDAY->value,
|
||||
startTime: '08:00',
|
||||
endTime: '09:00',
|
||||
room: null,
|
||||
updatedBy: self::UPDATER_ID,
|
||||
);
|
||||
|
||||
$result = ($this->handler)($command);
|
||||
|
||||
$newSlot = $result['newSlot'];
|
||||
self::assertNotNull($newSlot);
|
||||
self::assertSame(DayOfWeek::MONDAY, $newSlot->dayOfWeek);
|
||||
// recurrenceStart must be the Monday of the occurrence week (2026-10-12),
|
||||
// not the occurrence date (2026-10-14), so the slot is visible this week
|
||||
self::assertSame('2026-10-12', $newSlot->recurrenceStart->format('Y-m-d'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function allFutureWithNoOriginalEndUsesNullForNewSlotEnd(): void
|
||||
{
|
||||
@@ -149,6 +184,7 @@ final class UpdateRecurringSlotHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
private function createAndSaveSlot(
|
||||
DayOfWeek $dayOfWeek = DayOfWeek::MONDAY,
|
||||
?DateTimeImmutable $recurrenceStart = null,
|
||||
?DateTimeImmutable $recurrenceEnd = null,
|
||||
): ScheduleSlot {
|
||||
@@ -157,7 +193,7 @@ final class UpdateRecurringSlotHandlerTest extends TestCase
|
||||
classId: ClassId::fromString(self::CLASS_ID),
|
||||
subjectId: SubjectId::fromString(self::SUBJECT_ID),
|
||||
teacherId: UserId::fromString(self::TEACHER_ID),
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
dayOfWeek: $dayOfWeek,
|
||||
timeSlot: new TimeSlot('08:00', '09:00'),
|
||||
room: null,
|
||||
isRecurring: true,
|
||||
|
||||
Reference in New Issue
Block a user