Add company CRUD, admin sidebar order, partner/company pages
Some checks failed
Staging Build / build (push) Failing after 25s
Some checks failed
Staging Build / build (push) Failing after 25s
This commit is contained in:
@@ -1,49 +1,33 @@
|
||||
'use server'
|
||||
|
||||
import { createAdminClient } from '@/lib/supabase/admin'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
|
||||
export async function getCompanies() {
|
||||
const admin = createAdminClient()
|
||||
const { data, error } = await admin
|
||||
.from('companies')
|
||||
.select('id, name, created_at')
|
||||
.order('name', { ascending: true })
|
||||
const { data, error } = await admin.from('companies').select('*')
|
||||
if (error) throw error
|
||||
return data || []
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createCompany(name: string) {
|
||||
const admin = createAdminClient()
|
||||
const { data, error } = await admin
|
||||
.from('companies')
|
||||
.insert({ name: name.trim() })
|
||||
.select()
|
||||
.single()
|
||||
const { data, error } = await admin.from('companies').insert({ name }).single()
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/companies')
|
||||
return data
|
||||
}
|
||||
|
||||
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
|
||||
revalidatePath('/admin/companies')
|
||||
revalidatePath('/admin/users')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteCompany(id: string) {
|
||||
const admin = createAdminClient()
|
||||
const { error } = await admin
|
||||
.from('companies')
|
||||
.delete()
|
||||
.eq('id', id)
|
||||
const { error } = await admin.from('companies').delete().eq('id', id)
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/companies')
|
||||
revalidatePath('/admin/users')
|
||||
}
|
||||
|
||||
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')
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user