Feat: Implement comprehensive audit logging for Halls, Packages, and Reservations
This commit is contained in:
37
src/app/dashboard/halls/[id]/actions.ts
Normal file
37
src/app/dashboard/halls/[id]/actions.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
'use server'
|
||||
|
||||
import { createClient } from "@/lib/supabase/server"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { logAction } from "@/lib/logger"
|
||||
|
||||
export async function deleteHall(id: string) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase
|
||||
.from('halls')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
await logAction('delete_hall', 'hall', id)
|
||||
revalidatePath('/dashboard/halls')
|
||||
}
|
||||
|
||||
export async function updateHall(id: string, data: { name: string; capacity: number; description?: string }) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase
|
||||
.from('halls')
|
||||
.update({
|
||||
name: data.name,
|
||||
capacity: data.capacity,
|
||||
description: data.description,
|
||||
})
|
||||
.eq('id', id)
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
await logAction('update_hall', 'hall', id, data)
|
||||
revalidatePath('/dashboard/halls')
|
||||
}
|
||||
@@ -3,18 +3,25 @@
|
||||
import { createClient } from "@/lib/supabase/server"
|
||||
import { revalidatePath } from "next/cache"
|
||||
|
||||
import { logAction } from "@/lib/logger"
|
||||
|
||||
export async function createHall(data: { name: string; capacity: number; description?: string }) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase.from('halls').insert({
|
||||
const { data: newHall, error } = await supabase.from('halls').insert({
|
||||
name: data.name,
|
||||
capacity: data.capacity,
|
||||
description: data.description,
|
||||
})
|
||||
}).select().single()
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message)
|
||||
}
|
||||
|
||||
await logAction('create_hall', 'hall', newHall.id, {
|
||||
name: data.name,
|
||||
capacity: data.capacity
|
||||
})
|
||||
|
||||
revalidatePath('/dashboard/halls')
|
||||
}
|
||||
|
||||
@@ -47,3 +47,17 @@ export async function updateStatus(id: string, status: string) {
|
||||
revalidatePath(`/dashboard/reservations/${id}`)
|
||||
revalidatePath('/dashboard/reservations')
|
||||
}
|
||||
|
||||
export async function deleteReservation(id: string) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase
|
||||
.from('reservations')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
await logAction('delete_reservation', 'reservation', id)
|
||||
revalidatePath('/dashboard/reservations')
|
||||
}
|
||||
|
||||
38
src/app/dashboard/settings/packages/[id]/actions.ts
Normal file
38
src/app/dashboard/settings/packages/[id]/actions.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
'use server'
|
||||
|
||||
import { createClient } from "@/lib/supabase/server"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { logAction } from "@/lib/logger"
|
||||
|
||||
export async function deletePackage(id: string) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase
|
||||
.from('packages')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
await logAction('delete_package', 'package', id)
|
||||
revalidatePath('/dashboard/settings/packages')
|
||||
}
|
||||
|
||||
export async function updatePackage(id: string, data: { name: string; price: number; description?: string; is_active: boolean }) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase
|
||||
.from('packages')
|
||||
.update({
|
||||
name: data.name,
|
||||
price: data.price,
|
||||
description: data.description,
|
||||
is_active: data.is_active,
|
||||
})
|
||||
.eq('id', id)
|
||||
|
||||
if (error) throw new Error(error.message)
|
||||
|
||||
await logAction('update_package', 'package', id, data)
|
||||
revalidatePath('/dashboard/settings/packages')
|
||||
}
|
||||
@@ -3,19 +3,26 @@
|
||||
import { createClient } from "@/lib/supabase/server"
|
||||
import { revalidatePath } from "next/cache"
|
||||
|
||||
import { logAction } from "@/lib/logger"
|
||||
|
||||
export async function createPackage(data: { name: string; price: number; description?: string; is_active: boolean }) {
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase.from('packages').insert({
|
||||
const { data: newPackage, error } = await supabase.from('packages').insert({
|
||||
name: data.name,
|
||||
price: data.price,
|
||||
description: data.description,
|
||||
is_active: data.is_active,
|
||||
})
|
||||
}).select().single()
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message)
|
||||
}
|
||||
|
||||
await logAction('create_package', 'package', newPackage.id, {
|
||||
name: data.name,
|
||||
price: data.price
|
||||
})
|
||||
|
||||
revalidatePath('/dashboard/settings/packages')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user