feat: add full CRUD management for product categories in admin panel
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user