Fix: Remove duplicated code in reservation actions
This commit is contained in:
@@ -1,33 +1,5 @@
|
|||||||
'use server'
|
'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 { createClient } from "@/lib/supabase/server"
|
||||||
import { revalidatePath } from "next/cache"
|
import { revalidatePath } from "next/cache"
|
||||||
import { redirect } from "next/navigation"
|
import { redirect } from "next/navigation"
|
||||||
|
|||||||
Reference in New Issue
Block a user