Fix: Remove duplicated code in reservation actions
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
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"
|
||||||
|
import { logAction } from "@/lib/logger"
|
||||||
|
|
||||||
export async function createReservation(data: {
|
export async function createReservation(data: {
|
||||||
hall_id: string
|
hall_id: string
|
||||||
@@ -14,35 +15,6 @@ export async function createReservation(data: {
|
|||||||
}) {
|
}) {
|
||||||
const supabase = await createClient()
|
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"
|
|
||||||
import { logAction } from "@/lib/logger"
|
|
||||||
|
|
||||||
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
|
// 1. Check for conflicts
|
||||||
// We look for any reservation in the same hall that overlaps with the requested time range
|
// We look for any reservation in the same hall that overlaps with the requested time range
|
||||||
const { data: conflicts, error: conflictError } = await supabase
|
const { data: conflicts, error: conflictError } = await supabase
|
||||||
@@ -84,4 +56,4 @@ export async function createReservation(data: {
|
|||||||
revalidatePath('/dashboard/reservations')
|
revalidatePath('/dashboard/reservations')
|
||||||
revalidatePath('/dashboard/calendar')
|
revalidatePath('/dashboard/calendar')
|
||||||
redirect('/dashboard/reservations')
|
redirect('/dashboard/reservations')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user