Add company CRUD, admin sidebar order, partner/company pages
Some checks failed
Staging Build / build (push) Failing after 25s

This commit is contained in:
DanielS
2026-06-24 23:05:15 +02:00
parent ac0b0f607d
commit 82c89b70bf

View File

@@ -1,49 +1,33 @@
'use server'
import { createAdminClient } from '@/lib/supabase/admin' import { createAdminClient } from '@/lib/supabase/admin'
import { revalidatePath } from 'next/cache' import { revalidatePath } from 'next/cache'
export async function getCompanies() { export async function getCompanies() {
const admin = createAdminClient() const admin = createAdminClient()
const { data, error } = await admin const { data, error } = await admin.from('companies').select('*')
.from('companies')
.select('id, name, created_at')
.order('name', { ascending: true })
if (error) throw error if (error) throw error
return data || [] return data
} }
export async function createCompany(name: string) { export async function createCompany(name: string) {
const admin = createAdminClient() const admin = createAdminClient()
const { data, error } = await admin const { data, error } = await admin.from('companies').insert({ name }).single()
.from('companies') if (error) throw error
.insert({ name: name.trim() }) revalidatePath('/admin/companies')
.select() return data
.single() }
export async function updateCompany(id: string, name: string) {
const admin = createAdminClient()
const { data, error } = await admin.from('companies').update({ name }).eq('id', id).single()
if (error) throw error if (error) throw error
revalidatePath('/admin/companies') revalidatePath('/admin/companies')
revalidatePath('/admin/users')
return data return data
} }
export async function deleteCompany(id: string) { export async function deleteCompany(id: string) {
const admin = createAdminClient() const admin = createAdminClient()
const { error } = await admin const { error } = await admin.from('companies').delete().eq('id', id)
.from('companies')
.delete()
.eq('id', id)
if (error) throw error if (error) throw error
revalidatePath('/admin/companies') revalidatePath('/admin/companies')
revalidatePath('/admin/users') return true
}
export async function assignCompanyToUser(userId: string, companyId: string | null) {
const admin = createAdminClient()
const { error } = await admin
.from('users')
.update({ company_id: companyId })
.eq('id', userId)
if (error) throw error
revalidatePath('/admin/users')
revalidatePath('/admin/einstellungen')
} }