first commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
// Default settings
|
||||
const DEFAULT_SETTINGS: Record<string, string> = {
|
||||
customerSupportTicketsEnabled: 'false',
|
||||
// Vertrags-Cockpit: Fristenschwellen (in Tagen)
|
||||
deadlineCriticalDays: '14', // Rot: Kritisch
|
||||
deadlineWarningDays: '42', // Gelb: Warnung (6 Wochen)
|
||||
deadlineOkDays: '90', // Grün: OK (3 Monate)
|
||||
};
|
||||
|
||||
export async function getSetting(key: string): Promise<string | null> {
|
||||
const setting = await prisma.appSetting.findUnique({
|
||||
where: { key },
|
||||
});
|
||||
|
||||
if (setting) {
|
||||
return setting.value;
|
||||
}
|
||||
|
||||
// Return default if exists
|
||||
return DEFAULT_SETTINGS[key] ?? null;
|
||||
}
|
||||
|
||||
export async function getSettingBool(key: string): Promise<boolean> {
|
||||
const value = await getSetting(key);
|
||||
return value === 'true';
|
||||
}
|
||||
|
||||
export async function setSetting(key: string, value: string): Promise<void> {
|
||||
await prisma.appSetting.upsert({
|
||||
where: { key },
|
||||
update: { value },
|
||||
create: { key, value },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAllSettings(): Promise<Record<string, string>> {
|
||||
const settings = await prisma.appSetting.findMany();
|
||||
|
||||
// Start with defaults, then override with stored values
|
||||
const result = { ...DEFAULT_SETTINGS };
|
||||
|
||||
for (const setting of settings) {
|
||||
result[setting.key] = setting.value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getPublicSettings(): Promise<Record<string, string>> {
|
||||
// Settings that should be available to all authenticated users (including customers)
|
||||
const publicKeys = ['customerSupportTicketsEnabled'];
|
||||
const allSettings = await getAllSettings();
|
||||
|
||||
const result: Record<string, string> = {};
|
||||
for (const key of publicKeys) {
|
||||
if (key in allSettings) {
|
||||
result[key] = allSettings[key];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user