feat: add caching for backend objects
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user