Admin: lengths and prices per service; windows and group sessions on /slots
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
This commit is contained in:
parent
eac99b2abe
commit
636b59c706
12 changed files with 667 additions and 329 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Server helpers for the /slots page. Planning is pure and lives in
|
||||
// $shared/slots; this file does the PocketBase reads/writes around it.
|
||||
|
||||
import type { SlotDetail } from '$lib/slots';
|
||||
import type { SlotBooking, SlotDetail } from '$lib/slots';
|
||||
import type { createPocketBase } from '$lib/pb';
|
||||
|
||||
type Pb = ReturnType<typeof createPocketBase>;
|
||||
|
|
@ -10,21 +10,23 @@ type Pb = ReturnType<typeof createPocketBase>;
|
|||
const WRITE_CONCURRENCY = 5;
|
||||
|
||||
/**
|
||||
* Slots with their places and blocking, from the shop hook — the same
|
||||
* Slots with what's booked in them, from the shop hook — the same
|
||||
* availability rules the public shop uses (pocketbase/pb_hooks/shop/lib.js).
|
||||
* Either slots starting in `[from, to)` (optionally one service) or one slot by id.
|
||||
* Either slots starting in `[from, to)` (optionally those offering one
|
||||
* service) or one slot by id; `bookings` are all booked/held times starting
|
||||
* in that range (for one slot: around its start).
|
||||
*/
|
||||
export async function loadSlotDetails(pb: Pb, query: { from: string; to: string; item?: string } | { id: string }) {
|
||||
const { slots } = await pb.send<{ slots: SlotDetail[] }>('/api/shop/slots', {
|
||||
return pb.send<{ slots: SlotDetail[]; bookings: SlotBooking[] }>('/api/shop/slots', {
|
||||
query: { detail: 1, ...query },
|
||||
requestKey: null
|
||||
});
|
||||
return slots;
|
||||
}
|
||||
|
||||
/** One slot's details, or null if it doesn't exist (any other failure throws). */
|
||||
/** One slot's details and its own bookings, or null if it doesn't exist (any other failure throws). */
|
||||
export async function loadSlotDetail(pb: Pb, id: string) {
|
||||
return (await loadSlotDetails(pb, { id }))[0] ?? null;
|
||||
const { slots, bookings } = await loadSlotDetails(pb, { id });
|
||||
return slots[0] ? { ...slots[0], bookings: bookings.filter((b) => b.slot === id) } : null;
|
||||
}
|
||||
|
||||
export const seatsTaken = (slot: Pick<SlotDetail, 'booked' | 'held'>) => slot.booked + slot.held;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue