Files
webshop/shop/lib/actions/companies.ts
DanielS 85df922498
All checks were successful
Staging Build / build (push) Successful in 2m21s
feat: make company selection mandatory for partner role and add inline company creation in UserDialog
2026-06-25 01:43:53 +02:00

43 lines
1.3 KiB
TypeScript

'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('*')
if (error) throw error
return data
}
export async function createCompany(name: string) {
const admin = createAdminClient()
const { data, error } = await admin.from('companies').insert({ name }).select().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).select().single()
if (error) throw error
revalidatePath('/admin/companies')
return data
}
export async function deleteCompany(id: string) {
const admin = createAdminClient()
const { error } = await admin.from('companies').delete().eq('id', id)
if (error) throw error
revalidatePath('/admin/companies')
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')
return true
}