Registry Mirror
Skip to content

Conversation

@grandnode-dev

@grandnode-dev grandnode-dev commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Type: bugfix

Issue

The reservation calendar generator lived in BaseProductReservationController.GenerateCalendar (shared by Admin, Store and Vendor), untested, with several bugs:

  • The guard "a product with slots can't switch between day and hour/minute slots" compared (IntervalUnit)model.Interval instead of model.IntervalUnit, so the day-to-hour direction never fired.
  • GenerateCalendarModel had no validator. An empty date threw (500), and the ModelState branch was dead code.
  • A second Generate doubled hour and minute slots. Only day slots were de-duplicated, against an in-memory list of every slot of the product.
  • After 1000 slots the loop stopped inserting without telling anyone, while it kept walking the whole range behind catch { }.
  • Hour and minute slots were aligned to midnight, not to the start time: a 90-minute interval from 08:00 gave 09:00, 10:30… instead of 08:00, 09:30…
  • The product fields (interval, unit, both dates) were saved before the generation could fail.

Solution

  • IProductReservationService.GenerateCalendar(product, ReservationCalendarPlan) returns a ReservationCalendarResult (created, skipped, limit reached, unit changed):
    • day plan: one slot per selected day of the week for the resource (no quantity, no parameter); minute/hour plan: from the start time to the end time (included) of each selected day (no resource);
    • the existing slots of the range are counted per date, resource and parameter. Only the missing quantity is added, so Generate can be run again and raising the quantity adds the difference;
    • more than ReservationCalendarPlan.MaxSlots (1000) new slots: nothing is written and the limit is reported, so no calendar is left half-generated;
    • a day ↔ hour/minute change on a product that has slots is rejected before anything is written;
    • the read of existing slots and the inserts run under the product's lock that TryBook already takes, so two generations at once (a double click, two staff members) add the plan once;
    • a slot is stored as before: a day slot keeps the resource as posted, null when the field is empty, because FindGroupToBook groups by the stored resource and a "" next to null would split one resource in two.
  • GenerateCalendarModelValidator: both dates required, end ≥ start, interval > 0, a known unit, at least one day of the week; for minute/hour units, quantity > 0, an interval shorter than a day (their slots fill the hours of each day; a longer step is a calendar by days) and the end time not before the start time. Equal times are allowed: the end time is the last slot of a day, so they give one slot a day.
  • The controller is thin: validation → service → product fields only after a successful generation → { success, message } with the counts.
  • The Calendar tab shows the result (or the errors) in a status line above the grid instead of alert(). GrandAdmin has no notification widget, so an inline role="status" alert is the smallest fit.
  • New resources (admin + vendor) in DefaultLanguage.xml and Upgrade/en_250.xml.

Left as they are, on purpose:

  • No bulk insert. IRepository<T> has no InsertMany. Adding one would change a shared API with four implementations, including the auditing ones. Slots still go through InsertProductReservation, one entity event each, now capped at 1000.
  • No rollback when an insert fails midway: the repository has no transactions, as before. Generate again adds only what is missing.
  • The unit-change guard reads Product.IntervalUnitId, as before: slots do not store their unit.
  • Time zones stay as today (R7). This includes a spring-forward day, where a local time that does not exist maps to the same UTC instant as the hour after it. Slots are compared as instants, so Generate recognises the slots it wrote itself on the same server. A day slot written under another time zone (e.g. stored at 00:00 UTC by a server in UTC, then generated again on a CET server, which writes 23:00 UTC) is not treated as the same day. The old code matched those only by accident: it compared ticks while ignoring the kind, and that also stopped it from recognising its own day slots on a non-UTC server.

Breaking changes

None. IProductReservationService gains a method.

Testing

Automated: ProductReservationServiceTests (real MongoDB test repository, run in CET: day, minute alignment, week-day filter, re-run adds only the missing quantity, another parameter/resource is not a duplicate, limit, both unit-change directions), GenerateCalendarModelValidatorTests, BaseProductReservationControllerTests (generator cases replaced). Catalog, Checkout and Admin test projects pass in full.

Manual (done on a store with sample data on a CET server):

  1. Product with hour slots (e.g. 09:00–16:00, parameter Beginner) → Calendar tab → generate the same day and hours again → "Slots added: 0. Already in the calendar: 8."; with quantity 2 → 8 added; again → 0 added, 16 skipped.
  2. Same product, unit Day → "You can't change interval…", nothing written, product fields unchanged.
  3. Minute unit, 00:00–23:59, interval 1 → the limit message, nothing written.
  4. Clear the start date and every day of the week → both validation messages.
  5. Interval 90 minutes from 09:00 to 12:00 → slots at 09:00, 10:30, 12:00.
  6. The same in the Vendor panel (vendor resources). In the Store panel the access check is unchanged.

The generator moves from BaseProductReservationController into
IProductReservationService.GenerateCalendar and its bugs are fixed:

- the guard against switching between day and hour slots compared the
  interval instead of the unit, so it never fired;
- GenerateCalendarModel had no validator: an empty date was a 500 and
  the ModelState branch was dead;
- a second Generate doubled hour and minute slots; now only the missing
  quantity of a date, resource and parameter is added;
- more than 1000 slots stopped silently mid-range behind catch {}; now
  nothing is written and the limit is reported;
- hour slots were aligned to midnight instead of the start time;
- the product fields were saved before the generation could fail.

The tab reports the slots added and skipped in a status line instead of
alert().
Copilot AI balanced review requested due to automatic review settings November 29, 2026 16:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Review fixes for the calendar generator:

- a day slot without a resource is stored as null again, as before:
  FindGroupToBook groups by the stored resource, so "" next to null
  split one resource in two and a range across both could not be booked;
- the read of existing slots and the inserts run under the product's
  lock that TryBook takes, so two generations at once add the plan once;
- the range query ends on the last tick of the end date instead of a day
  after it, which overflowed on 9999-12-31;
- minute and hour intervals must be shorter than a day: their slots fill
  the hours of each day, and a huge interval overflowed TimeSpan.
@grandnode-dev
grandnode-dev merged commit 77ba567 into develop Nov 29, 2026
9 checks passed
@grandnode-dev
grandnode-dev deleted the fix/reservation-calendar-generator branch November 29, 2026 17:42
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