76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import { Response } from 'express';
|
|
import * as appSettingService from '../services/appSetting.service.js';
|
|
import { ApiResponse, AuthRequest } from '../types/index.js';
|
|
|
|
export async function getAllSettings(req: AuthRequest, res: Response): Promise<void> {
|
|
try {
|
|
const settings = await appSettingService.getAllSettings();
|
|
res.json({ success: true, data: settings } as ApiResponse);
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Fehler beim Laden der Einstellungen',
|
|
} as ApiResponse);
|
|
}
|
|
}
|
|
|
|
export async function getPublicSettings(req: AuthRequest, res: Response): Promise<void> {
|
|
try {
|
|
const settings = await appSettingService.getPublicSettings();
|
|
res.json({ success: true, data: settings } as ApiResponse);
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Fehler beim Laden der Einstellungen',
|
|
} as ApiResponse);
|
|
}
|
|
}
|
|
|
|
export async function updateSetting(req: AuthRequest, res: Response): Promise<void> {
|
|
try {
|
|
const { key } = req.params;
|
|
const { value } = req.body;
|
|
|
|
if (value === undefined) {
|
|
res.status(400).json({
|
|
success: false,
|
|
error: 'Wert ist erforderlich',
|
|
} as ApiResponse);
|
|
return;
|
|
}
|
|
|
|
await appSettingService.setSetting(key, String(value));
|
|
res.json({ success: true, message: 'Einstellung gespeichert' } as ApiResponse);
|
|
} catch (error) {
|
|
res.status(400).json({
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Fehler beim Speichern der Einstellung',
|
|
} as ApiResponse);
|
|
}
|
|
}
|
|
|
|
export async function updateSettings(req: AuthRequest, res: Response): Promise<void> {
|
|
try {
|
|
const settings = req.body;
|
|
|
|
if (!settings || typeof settings !== 'object') {
|
|
res.status(400).json({
|
|
success: false,
|
|
error: 'Einstellungen sind erforderlich',
|
|
} as ApiResponse);
|
|
return;
|
|
}
|
|
|
|
for (const [key, value] of Object.entries(settings)) {
|
|
await appSettingService.setSetting(key, String(value));
|
|
}
|
|
|
|
res.json({ success: true, message: 'Einstellungen gespeichert' } as ApiResponse);
|
|
} catch (error) {
|
|
res.status(400).json({
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Fehler beim Speichern der Einstellungen',
|
|
} as ApiResponse);
|
|
}
|
|
}
|