Services with several lengths; slots become time windows #6

Merged
reudy merged 7 commits from session/change-slots-behavior into main 2026-10-25 22:16:35 +01:00
Member

Why

Today one massage in three lengths means three services, and every bookable time is a slot of one service. The studio asked for:

  • one service with several lengths, each with its own price. Customers pick the length with a slider and the price follows it.
  • availability windows: "I can work 09:00–12:00, and these services can be booked in it". Each booking takes its time plus get-ready time out of the window; the rest stays bookable.

Bundles, vouchers and codes are a follow-up PR on top of this.

What changes

Schema (migration 1793100000_durations_and_time_windows.js, mirrored in pb_schema.json)

  • items.durations — [{ minutes, price }]; items.duration goes. items.price is kept as the lowest length price (products: unchanged).
  • slots.kind = window | session, slots.items (multiple), slots.startTimes = grid | edges with slots.gridMinutes (the step); slots.item goes.
  • basket_lines.start/minutes, order_lines.minutes: a booking records its own time, so availability no longer depends on the slot.
  • Existing slots are deleted (agreed with the client: start fresh). Before that, every order line gets minutes from its slot, so paid bookings keep blocking their time. Basket holds on old slots are dropped.

Availability (all still in pocketbase/pb_hooks/shop/lib.js)

  • One practitioner: no booking may overlap another, get-ready time included.
  • Window start times: grid = fixed steps, chosen per window (gridMinutes: 10, 15, 20, 30, 45 or 60; default 30); edges = only at the start or end of each free stretch, so the window shrinks from either end and no gaps are left. A booking must fit inside the window; its get-ready time may run past the end.
  • Group sessions keep places. Any place taken makes the session's time busy for windows, and a booking in a window blocks an overlapping session.
  • GET /api/shop/slots?item=&minutes=&from=&to= lists times for one service and length, plus next when the range is empty. The Shop block fetches it via GET /api/slots in each app instead of shipping every slot in the layout.
  • The price is the service's price for the booked length, re-read at checkout and when the order is created.

Admin

  • Services: Lengths and prices rows.
  • Slots: Add window (date, hours, services, start-times mode) and Add group session (service, length, start, places). The day view shows free time and bookings. Generate, copy and clear handle both kinds. Windows can't overlap each other and can't shrink past a booking.

Public: service cards show "from" the lowest price; after Book, a slider picks the length (the price follows) above the date picker; the picker loads times for the chosen length and reloads after a booking. Checkout, emails and orders show the booked length.

Tested

  • Migration on a copy of main's schema with old-style data: old slots are removed, the paid booking keeps its time (60 min), the stale hold is dropped, and services get one length at their old price. Fresh install (pb_schema.json import) works too.
  • 46 API scenarios against PocketBase 0.23.12 all pass. They cover grid start times (30-min default and a 15-min step), edges start times, get-ready time, overlap refusals, a service not in the window, group-session places and blocking in both directions, a booking that runs to the window's end, the price per length, removal freeing time, next, and admin detail/auth.
  • Checkout total and the Stripe webhook (signed test event, stripe-mock): the order line gets the right start, length and price, and the paid time stays blocked.
  • svelte-check: 0 errors in both apps. All warnings are in files this PR doesn't touch.
  • Browser (Playwright) on the built images: services with three lengths, windows (an overlapping window is refused), a group session, the month calendar; on the public side the slider (€80 → €140), the picker's times, booking 09:00 shrinking the window to 10:30+, and the basket and checkout line.

Not tested: real Stripe payment, actual email sending (the email code path is unchanged apart from the end time), Copy-a-week and Clear in the browser (same server code paths as Generate, covered by type-checks only), and mobile layouts.

Deploying

The migration runs on the next PocketBase start and deletes all existing slots. Back up pb_data first. Then set each service's lengths and prices under Services & products, and create windows under Slots.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW

## Why Today one massage in three lengths means three services, and every bookable time is a slot of one service. The studio asked for: - **one service with several lengths**, each with its own price. Customers pick the length with a slider and the price follows it. - **availability windows**: "I can work 09:00–12:00, and these services can be booked in it". Each booking takes its time plus get-ready time out of the window; the rest stays bookable. Bundles, vouchers and codes are a follow-up PR on top of this. ## What changes **Schema** (migration `1793100000_durations_and_time_windows.js`, mirrored in `pb_schema.json`) - `items.durations` — `[{ minutes, price }]`; `items.duration` goes. `items.price` is kept as the lowest length price (products: unchanged). - `slots.kind` = `window` | `session`, `slots.items` (multiple), `slots.startTimes` = `grid` | `edges` with `slots.gridMinutes` (the step); `slots.item` goes. - `basket_lines.start/minutes`, `order_lines.minutes`: a booking records its own time, so availability no longer depends on the slot. - **Existing slots are deleted** (agreed with the client: start fresh). Before that, every order line gets `minutes` from its slot, so paid bookings keep blocking their time. Basket holds on old slots are dropped. **Availability** (all still in `pocketbase/pb_hooks/shop/lib.js`) - One practitioner: no booking may overlap another, get-ready time included. - Window start times: `grid` = fixed steps, chosen per window (`gridMinutes`: 10, 15, 20, 30, 45 or 60; default 30); `edges` = only at the start or end of each free stretch, so the window shrinks from either end and no gaps are left. A booking must fit inside the window; its get-ready time may run past the end. - Group sessions keep places. Any place taken makes the session's time busy for windows, and a booking in a window blocks an overlapping session. - `GET /api/shop/slots?item=&minutes=&from=&to=` lists times for one service and length, plus `next` when the range is empty. The Shop block fetches it via `GET /api/slots` in each app instead of shipping every slot in the layout. - The price is the service's price for the booked length, re-read at checkout and when the order is created. **Admin** - Services: *Lengths and prices* rows. - Slots: *Add window* (date, hours, services, start-times mode) and *Add group session* (service, length, start, places). The day view shows free time and bookings. Generate, copy and clear handle both kinds. Windows can't overlap each other and can't shrink past a booking. **Public**: service cards show "from" the lowest price; after **Book**, a slider picks the length (the price follows) above the date picker; the picker loads times for the chosen length and reloads after a booking. Checkout, emails and orders show the booked length. ## Tested - Migration on a copy of `main`'s schema with old-style data: old slots are removed, the paid booking keeps its time (60 min), the stale hold is dropped, and services get one length at their old price. Fresh install (`pb_schema.json` import) works too. - 46 API scenarios against PocketBase 0.23.12 all pass. They cover grid start times (30-min default and a 15-min step), edges start times, get-ready time, overlap refusals, a service not in the window, group-session places and blocking in both directions, a booking that runs to the window's end, the price per length, removal freeing time, `next`, and admin detail/auth. - Checkout total and the Stripe webhook (signed test event, `stripe-mock`): the order line gets the right start, length and price, and the paid time stays blocked. - `svelte-check`: 0 errors in both apps. All warnings are in files this PR doesn't touch. - Browser (Playwright) on the built images: services with three lengths, windows (an overlapping window is refused), a group session, the month calendar; on the public side the slider (€80 → €140), the picker's times, booking 09:00 shrinking the window to 10:30+, and the basket and checkout line. **Not tested:** real Stripe payment, actual email sending (the email code path is unchanged apart from the end time), Copy-a-week and Clear in the browser (same server code paths as Generate, covered by type-checks only), and mobile layouts. ## Deploying The migration runs on the next PocketBase start and **deletes all existing slots**. Back up `pb_data` first. Then set each service's lengths and prices under *Services & products*, and create windows under *Slots*. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 5 commits 2026-10-25 21:13:10 +01:00
A service now has `durations` ([{ minutes, price }]) instead of one
duration and price. A slot is either a `window` (a stretch of time with the
services that can be booked in it, start times every 30 min or only at the
edges of the free time) or a `session` (one service, fixed time, places —
the old group slot). Basket and order lines carry their own start and
minutes, so availability is computed from bookings alone.

The migration keeps paid bookings blocking their time (order lines get
minutes from their slot), then deletes the old slots — agreed: start fresh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Service cards step through their lengths with a slider and the price
follows. The time picker loads bookable times for the chosen length and
the months on screen from GET /api/slots (a proxy to the shop hook in each
app), and reloads when the basket's bookings change. Checkout, emails and
the basket show each booking's own length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Services get rows of length + price. /slots creates windows (date, hours,
services, start-times mode) and group sessions (service, length, start,
places); the day view shows free time and bookings. Generate/copy/clear
handle both kinds; windows may not overlap and can't shrink past a booking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 1 commit 2026-10-25 21:56:07 +01:00
The card shows "from" the lowest price and the range of lengths; the
slider moves into the booking panel, above the date picker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
agent added 1 commit 2026-10-25 22:03:42 +01:00
A window on fixed steps now has gridMinutes; the admin picks it when
creating or generating windows, and copies keep it. Added to the
(unmerged, undeployed) time-windows migration and pb_schema.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
reudy merged commit 650de78bac into main 2026-10-25 22:16:35 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/domaino#6
No description provided.