feat(sync): add customer synchronization from lic server
All checks were successful
Staging Build / build (push) Successful in 3m0s

This commit is contained in:
DanielS
2026-07-15 22:48:10 +02:00
parent 3a090b7664
commit 5d3eed874c
3 changed files with 104 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ import {
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { getCompanies, createCompany, updateCompany, deleteCompany, syncCompaniesFromLicServer } from '@/lib/actions/companies'
import { getCompanies, createCompany, updateCompany, deleteCompany, syncCompaniesFromLicServer, syncCustomersFromLicServer } from '@/lib/actions/companies'
export default function CompaniesPage() {
const [companies, setCompanies] = useState<any[]>([])
@@ -42,8 +42,9 @@ export default function CompaniesPage() {
setSyncing(true)
setStatusMsg(null)
try {
const res = await syncCompaniesFromLicServer()
setStatusMsg(`${res.count} Partner erfolgreich vom LicServer importiert/aktualisiert.`)
const resCompanies = await syncCompaniesFromLicServer()
const resCustomers = await syncCustomersFromLicServer()
setStatusMsg(`${resCompanies.count} Partner und ${resCustomers.count} Kunden erfolgreich vom LicServer importiert.`)
setStatusType('success')
loadCompanies()
} catch (err: any) {

View File

@@ -0,0 +1,25 @@
import { NextRequest, NextResponse } from 'next/server'
import { syncCustomersFromLicServer } from '@/lib/actions/companies'
export const dynamic = 'force-dynamic'
export async function GET(req: NextRequest) {
// Check authorization header
const authHeader = req.headers.get('authorization')
const cronSecret = process.env.CRON_SECRET
// Secure the cron endpoint in production
if (process.env.NODE_ENV === 'production' && cronSecret) {
if (authHeader !== `Bearer ${cronSecret}`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
}
try {
const res = await syncCustomersFromLicServer()
return NextResponse.json({ success: true, count: res.count })
} catch (err: any) {
console.error('[cron] Customer sync failed:', err)
return NextResponse.json({ error: err.message || 'Sync failed' }, { status: 500 })
}
}