Shop: places per slot, and bookings block overlapping slots

Slots get a capacity (items.capacity is the service default). Booking
state is no longer stored on the slot: slotStates() in the shop hooks
counts places from paid order lines and live basket holds (heldUntil
moves to the basket line), and a slot with any place taken blocks every
overlapping slot of any service, including get-ready time.

GET /api/shop/slots lists bookable slots (public) or full detail for a
signed-in admin. add_slot takes seats and adds to an existing line;
group lines can change quantity. Checks and writes share one
transaction. Migration moves existing holds, drops the unique index and
slot status/heldUntil/order, and makes slots signed-in only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaXE9U7AmW3dfD2w6cbLfk
This commit is contained in:
agent 2026-10-24 08:26:37 +00:00
parent b52da79ec8
commit d7765fe605
7 changed files with 400 additions and 101 deletions

View file

@ -3,6 +3,18 @@
/// treats its input as untrusted. The basket id acts as the customer's
/// bearer token, exactly like the cookie it comes from.
// Slot availability (seats + cross-service blocking, see lib.js). Anyone
// gets the bookable future slots; a signed-in admin can ask for `detail`.
routerAdd('GET', '/api/shop/slots', (e) => {
const shop = require(`${__hooks}/shop/lib.js`);
const query = e.request.url.query();
if (query.get('detail')) {
if (!e.auth) throw new UnauthorizedError('Sign in to see slot details');
return e.json(200, { slots: shop.slotDetails($app, { from: query.get('from'), to: query.get('to'), item: query.get('item'), id: query.get('id') }) });
}
return e.json(200, { slots: shop.bookableSlots($app) });
});
routerAdd('GET', '/api/shop/basket/{id}', (e) => {
const shop = require(`${__hooks}/shop/lib.js`);
shop.sweepExpiredHolds($app);