diff --git a/.gitignore b/.gitignore index 1f3bf13..b0cf9c6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ coverage/ # draft files *.draft.json +# test data directories +app/test_data*/ + + diff --git a/src/pages/admin/settings.astro b/src/pages/admin/settings.astro new file mode 100644 index 0000000..d3436ba --- /dev/null +++ b/src/pages/admin/settings.astro @@ -0,0 +1,75 @@ +--- +// src/pages/admin/settings.astro +import Layout from '../../layouts/Layout.astro'; +import { loadWaasConfigs } from '../../utils/configLoader'; + +export const prerender = false; + +const userAgent = Astro.request.headers.get('user-agent') ?? ''; +const { siteConfig } = loadWaasConfigs(userAgent); +const info = (siteConfig as any).site_info || {}; +--- + + + + + + ← Zurück zum Seiten-Dashboard + Globale Stammdaten & SEO + Diese Daten werden für automatisches Data Binding & Kontakt-Infos genutzt. + + + + + + Unternehmensdaten + + + + Firmenname / Website-Titel + + + + + E-Mail Adresse + + + + + Telefonnummer + + + + + Adresse / Standort + + + + + + + + 💾 Stammdaten Speichern + + + + + + + diff --git a/src/pages/api/admin/settings/update.ts b/src/pages/api/admin/settings/update.ts new file mode 100644 index 0000000..0e64e97 --- /dev/null +++ b/src/pages/api/admin/settings/update.ts @@ -0,0 +1,41 @@ +import type { APIRoute } from 'astro'; +import fs from 'node:fs/promises'; +import path from 'node:path'; + +export const prerender = false; + +const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data'); + +export const POST: APIRoute = async ({ request }) => { + try { + const { site_info, navigation } = await request.json(); + + if (!site_info || typeof site_info !== 'object') { + return new Response(JSON.stringify({ error: 'Gültige site_info Daten erforderlich' }), { status: 400 }); + } + + const configPath = path.join(DATA_DIR, 'site.config.json'); + let config: any = {}; + + try { + const raw = await fs.readFile(configPath, 'utf-8'); + config = JSON.parse(raw); + } catch { + // Fallback bei neuer Instanz + config = { site_info: {}, pages: [], navigation: [] }; + } + + // Update der globalen Eigenschaften + config.site_info = { ...config.site_info, ...site_info }; + if (Array.isArray(navigation)) { + config.navigation = navigation; + } + + await fs.mkdir(DATA_DIR, { recursive: true }); + await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8'); + + return new Response(JSON.stringify({ success: true, site_info: config.site_info }), { status: 200 }); + } catch (error) { + return new Response(JSON.stringify({ error: 'Fehler beim Speichern der Einstellungen' }), { status: 500 }); + } +}; diff --git a/tests/siteSettings.test.ts b/tests/siteSettings.test.ts new file mode 100644 index 0000000..5bdeeef --- /dev/null +++ b/tests/siteSettings.test.ts @@ -0,0 +1,33 @@ +import { describe, it, expect, beforeEach } from 'vitest'; +import fs from 'node:fs/promises'; +import path from 'node:path'; + +const DATA_DIR = path.join(process.cwd(), 'app', 'test_data_site_settings'); +const configPath = path.join(DATA_DIR, 'site.config.json'); + +describe('Global Site Settings API Test', () => { + beforeEach(async () => { + await fs.mkdir(DATA_DIR, { recursive: true }); + const dummyConfig = { + site_info: { title: 'Alte Firma', phone: '0123456' }, + navigation: [{ label: 'Home', page_id: 'page_1' }] + }; + await fs.writeFile(configPath, JSON.stringify(dummyConfig, null, 2), 'utf-8'); + }); + + it('soll globale Stammdaten in site.config.json aktualisieren', async () => { + const raw = await fs.readFile(configPath, 'utf-8'); + const config = JSON.parse(raw); + + config.site_info.title = 'N&D IT Solutions GmbH'; + config.site_info.phone = '+49 7473 123456'; + + await fs.writeFile(configPath, JSON.stringify(config, null, 2), 'utf-8'); + + const updatedRaw = await fs.readFile(configPath, 'utf-8'); + const updatedConfig = JSON.parse(updatedRaw); + + expect(updatedConfig.site_info.title).toBe('N&D IT Solutions GmbH'); + expect(updatedConfig.site_info.phone).toBe('+49 7473 123456'); + }); +});
Diese Daten werden für automatisches Data Binding & Kontakt-Infos genutzt.