Oouhammmourachid /
Public
ouhammmourachid / bookings
PublicAppointment and reservation backend: bookable resources with opening hours, an availability endpoint, and overlap checks so the same slot can't be booked twice.
- Other
- 0 deploys
- 0 forks
Bookings: resources, slots and no double-booking
Appointment and reservation backend: bookable resources with opening hours, an availability endpoint, and overlap checks so the same slot can't be booked twice.
What you get
- Resources (rooms, desks, people, courts...) with opening hours and slot length
GET /api/resources/{id}/availability?date=YYYY-MM-DDlists free slots- Overlapping bookings are refused
- Bookings must be in the future and inside opening hours
- Users cancel their own bookings; resource owners see every booking on their resources
Collections
resources
| Field | Type | Notes |
|---|---|---|
name (required) | text | |
description | text | |
owner (required) | relation → users | Set by a hook to the signed-in user |
slot_minutes (required) | number | Slot length for availability |
open_hour | number | UTC hour, 0-23 |
close_hour (required) | number | UTC hour, 1-24 |
disabled | bool | Stop taking bookings |
| Action | Who can do it |
|---|---|
| List / view | disabled = false || owner = @request.auth.id |
| Create | signed-in users |
| Update | owner = @request.auth.id |
| Delete | owner = @request.auth.id |
bookings
Bookings are cancelled, not deleted, so history is kept.
| Field | Type | Notes |
|---|---|---|
resource (required) | relation → resources | |
user (required) | relation → users | Set by a hook to the signed-in user |
starts_at (required) | date | UTC |
ends_at (required) | date | UTC |
status | select | confirmed or cancelled |
note | text |
| Action | Who can do it |
|---|---|
| List / view | user = @request.auth.id || resource.owner = @request.auth.id |
| Create | signed-in users |
| Update | user = @request.auth.id || resource.owner = @request.auth.id |
| Delete | superusers only |
Hooks
All hooks are in pb_hooks/main.pb.js and commented.
Quick start
import PocketBase from "pocketbase"
const pb = new PocketBase("https://YOUR-INSTANCE.pocketshub.com")
const { slots } = await pb.send(`/api/resources/${resourceId}/availability?date=2027-01-15`, {})
await pb.collection("bookings").create({
resource: resourceId, starts_at: slots[0].starts_at, ends_at: slots[0].ends_at, note: "Team sync",
})
// Cancel:
await pb.collection("bookings").update(bookingId, { status: "cancelled" })
Notes
- All times are UTC. Convert to the user's timezone in your frontend.
License
MIT
2 collections, 1 relation. Hover a collection to trace its relations