From 806f3ee77054526792c50dbcc52cb28f4f074e5f Mon Sep 17 00:00:00 2001 From: richarjiang Date: Thu, 10 Sep 2026 22:32:32 +0800 Subject: [PATCH] fix(server): preserve admin 'rest day' intent across cron runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit publishDaySlots used to DELETE the TimeSlot rows of a day that an admin just 'cleared', which made the nightly slot-generation cron resurrect the default schedule the next morning — a real production bug where classes would reappear on a teacher's rest day. Changes: - publishDaySlots now CLOSEs (never DELETEs) orphaned rows, and materializes the default template for days with no rows so an empty publish still records intent. update on existing rows preserves their current status, so re-publishing the page cannot silently reopen a CLOSED rest day. - SlotGeneratorService.generateSlots pre-fetches dates that already have any TimeSlot row and skips them, so the cron no longer overwrites admin-touched days even when admin only set status without changing times. - SlotGeneratorService.prunePastClosedSlots (new) deletes past CLOSED slots with no bookings, scheduled nightly at 02:35, so the 'no DELETE' rule above does not leak rows forever. - schedule.vue surfaces the CLOSED state with a grey '已关闭' badge and card style. Tests: 12 new specs across time-slot.service.spec.ts (publishDaySlots behaviour) and slot-generator.service.spec.ts (skip touched dates + prune conditions). Full suite: 315 / 315 passing. --- packages/app/src/pages/admin/schedule.vue | 15 ++ .../server/src/scheduler/scheduler.service.ts | 11 + .../__tests__/slot-generator.service.spec.ts | 123 +++++++++++ .../__tests__/time-slot.service.spec.ts | 193 ++++++++++++++++++ .../src/time-slot/slot-generator.service.ts | 76 ++++++- .../server/src/time-slot/time-slot.service.ts | 84 ++++++-- 6 files changed, 480 insertions(+), 22 deletions(-) diff --git a/packages/app/src/pages/admin/schedule.vue b/packages/app/src/pages/admin/schedule.vue index a550a37..b15c5f2 100644 --- a/packages/app/src/pages/admin/schedule.vue +++ b/packages/app/src/pages/admin/schedule.vue @@ -160,6 +160,7 @@