Fix: Remove duplicated code in reservation actions

This commit is contained in:
2025-12-03 22:36:31 +03:00
parent 8e3cb406af
commit fdc242b076

View File

@@ -1,33 +1,5 @@
'use server'
import { createClient } from "@/lib/supabase/server"
import { revalidatePath } from "next/cache"
import { redirect } from "next/navigation"
export async function createReservation(data: {
hall_id: string
customer_id: string
package_id?: string
start_time: string
end_time: string
notes?: string
}) {
const supabase = await createClient()
// 1. Check for conflicts
// We look for any reservation in the same hall that overlaps with the requested time range
const { data: conflicts, error: conflictError } = await supabase
.from('reservations')
.select('id')
.eq('hall_id', data.hall_id)
.neq('status', 'cancelled') // Ignore cancelled bookings
.or(`and(start_time.lte.${data.end_time},end_time.gte.${data.start_time})`)
if (conflictError) {
throw new Error("Müsaitlik kontrolü yapılırken hata oluştu: " + conflictError.message)
}
'use server'
import { createClient } from "@/lib/supabase/server"
import { revalidatePath } from "next/cache"
import { redirect } from "next/navigation"