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,20 +3,18 @@ import { getFileUrl } from '../pb';
import type { ItemRecord, SlotRecord } from '../types';
/**
* Active items and future available slots, shaped for the Shop/Checkout
* Active items and bookable future slots, shaped for the Shop/Checkout
* blocks. Used by the public layout and the admin draft preview so both
* render the same shop.
*
* Works with an anonymous client: the API rules expose active items,
* available slots and media publicly. Errors propagate.
* Works with an anonymous client: active items and media are public, and
* slots come from the shop hook (GET /api/shop/slots), which leaves out
* full slots and slots blocked by an overlapping booking. Errors propagate.
*/
export async function loadShopData(pb: PocketBase): Promise<{ items: ItemRecord[]; slots: SlotRecord[] }> {
const [itemRecords, slotRecords] = await Promise.all([
const [itemRecords, { slots }] = await Promise.all([
pb.collection('items').getFullList({ filter: 'active = true', sort: 'name', expand: 'image' }),
pb.collection('slots').getFullList({
filter: pb.filter("status = 'available' && start >= {:now}", { now: new Date() }),
sort: 'start'
})
pb.send<{ slots: SlotRecord[] }>('/api/shop/slots', { requestKey: null })
]);
const items = itemRecords.map((record): ItemRecord => {
@ -32,22 +30,10 @@ export async function loadShopData(pb: PocketBase): Promise<{ items: ItemRecord[
stock: record.stock ?? null,
duration: record.duration ?? null,
bufferMinutes: record.bufferMinutes ?? null,
capacity: record.capacity ?? null,
active: record.active
};
});
const slots = slotRecords.map(
(record): SlotRecord => ({
id: record.id,
item: record.item,
start: record.start,
end: record.end || '',
status: record.status,
heldUntil: record.heldUntil || null,
order: record.order || null,
notes: record.notes || ''
})
);
return { items, slots };
}