feat: add full CRUD management for product categories in admin panel

This commit is contained in:
DanielS
2026-05-01 00:57:33 +02:00
parent 1dd2756e22
commit 826cf33183
4 changed files with 341 additions and 0 deletions

View File

@@ -23,9 +23,47 @@ export async function getCategories() {
.order('name', { ascending: true })
if (error) throw error
return data as Category[]
}
export async function createCategory(category: Omit<Category, 'id' | 'created_at'>) {
const supabase = await createClient()
const { data, error } = await supabase
.from('categories')
.insert([category])
.select()
.single()
if (error) throw error
revalidatePath('/admin/categories')
revalidatePath('/order')
return data
}
export async function updateCategory(id: string, category: Partial<Category>) {
const supabase = await createClient()
const { error } = await supabase
.from('categories')
.update(category)
.eq('id', id)
if (error) throw error
revalidatePath('/admin/categories')
revalidatePath('/order')
}
export async function deleteCategory(id: string) {
const supabase = await createClient()
const { error } = await supabase
.from('categories')
.delete()
.eq('id', id)
if (error) throw error
revalidatePath('/admin/categories')
revalidatePath('/order')
}
export async function createProduct(product: Omit<Product, 'id' | 'created_at' | 'updated_at'>, modules: Omit<ProductModule, 'id' | 'product_id' | 'created_at'>[]) {
const supabase = await createClient()