feat: add caching for backend objects

This commit is contained in:
2026-04-21 19:38:57 -04:00
parent 5b4955f07e
commit 7f1e82acc2
14 changed files with 637 additions and 62 deletions

View File

@@ -110,6 +110,20 @@ Deno.serve(async (req: Request) => {
return errorResponse('invalid_dates', 'end_time must be after start_time', 400)
}
// ── Historical booking guard ────────────────────────────────────────────────
const isPast = endDate.getTime() < Date.now()
if (isPast) {
const { data: callerMember } = await adminClient
.from('members')
.select('role')
.eq('user_id', userId)
.single()
if (callerMember?.role !== 'admin') {
return errorResponse('historical_booking_not_allowed', 'Can not book a reservation in the past.', 422)
}
}
// ── 1. Load booking config ──────────────────────────────────────────────────
const { data: configRows, error: configErr } = await adminClient
.from('booking_config')
@@ -142,7 +156,7 @@ Deno.serve(async (req: Request) => {
if (boatErr || !boat) return errorResponse('not_found', 'Boat not found', 404)
if (!boat.booking_available) return errorResponse('boat_unavailable', 'This boat is currently out of service', 422)
if (boat.required_certs.length > 0) {
if (!isPast && boat.required_certs.length > 0) {
const { data: member } = await adminClient
.from('members')
.select('certifications')
@@ -164,7 +178,7 @@ Deno.serve(async (req: Request) => {
const advanceMs = config.open_session_advance_hours * 60 * 60 * 1000
const isOpenSession = startDate.getTime() - Date.now() <= advanceMs
if (!isOpenSession) {
if (!isPast && !isOpenSession) {
// ── 5. Weekly pre-booking limit ─────────────────────────────────────────
const weekStart = isoWeekStart(startDate)
const weekEnd = new Date(weekStart.getTime() + 7 * 24 * 60 * 60 * 1000)