feat(admin): add manual partner import from lic server
All checks were successful
Staging Build / build (push) Successful in 2m48s

This commit is contained in:
DanielS
2026-07-15 00:07:31 +02:00
parent a318a5e225
commit 3fb80e6404
2 changed files with 76 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
'use server'
import { createAdminClient } from '@/lib/supabase/admin'
import { revalidatePath, unstable_noStore as noStore } from 'next/cache'
import { getLicServerConfig } from './licserver-config'
export async function getCompanies() {
noStore()
@@ -219,3 +220,45 @@ export async function adminDeleteEndCustomer(id: string) {
return true
}
export async function syncCompaniesFromLicServer() {
const admin = createAdminClient()
const cfg = await getLicServerConfig()
if (!cfg.base_url || !cfg.api_key) {
throw new Error('LicServer ist nicht konfiguriert.')
}
const res = await fetch(`${cfg.base_url}/api-v1/partners?pageSize=1000`, {
headers: { 'X-Api-Key': cfg.api_key, 'Accept': 'application/json' },
signal: AbortSignal.timeout(10_000),
})
if (!res.ok) {
throw new Error(`Lizenzserver antwortete mit Fehler: HTTP ${res.status}`)
}
const result = await res.json()
const partners = result.items || []
if (partners.length === 0) {
return { success: true, count: 0 }
}
const upsertRows = partners.map((p: any) => ({
id: p.id,
name: p.name || 'Unbenannt',
email: p.email || null,
}))
const { error } = await admin
.from('companies')
.upsert(upsertRows, { onConflict: 'id' })
if (error) throw error
revalidatePath('/admin/companies')
revalidatePath('/admin/users')
return { success: true, count: partners.length }
}