Files
HealthLog/src/lib/app-settings.ts
T
Marc-André BombeckandClaude Opus 4.7 02b99553b9 chore(style): repo-wide prettier sweep before v1.4.6 tag
Long-overdue prettier sweep; prettier had drifted vs. checked-in code
across ~130 files (mostly long-argument line-break wrapping in TS and
table-padding in markdown). Pure formatting — no semantic changes —
and required to clear the v1.4.6 release gate's `pnpm format:check`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 02:27:17 +02:00

75 lines
1.9 KiB
TypeScript

import { prisma } from "@/lib/db";
import { getEvent } from "@/lib/logging/context";
export interface GlobalServiceAvailability {
telegramGlobal: boolean;
ntfyGlobal: boolean;
webPushGlobal: boolean;
apiGlobal: boolean;
moodLogGlobal: boolean;
}
export async function getGlobalServiceAvailability(): Promise<GlobalServiceAvailability> {
try {
const settings = await prisma.appSettings.findUnique({
where: { id: "singleton" },
select: {
telegramGlobal: true,
ntfyGlobal: true,
webPushGlobal: true,
apiGlobal: true,
moodLogGlobal: true,
},
});
return {
telegramGlobal: settings?.telegramGlobal ?? true,
ntfyGlobal: settings?.ntfyGlobal ?? true,
webPushGlobal: settings?.webPushGlobal ?? true,
apiGlobal: settings?.apiGlobal ?? true,
moodLogGlobal: settings?.moodLogGlobal ?? true,
};
} catch {
getEvent()?.addWarning("Failed to load app settings, using defaults");
return {
telegramGlobal: true,
ntfyGlobal: true,
webPushGlobal: true,
apiGlobal: true,
moodLogGlobal: true,
};
}
}
export async function isApiGloballyEnabled(): Promise<boolean> {
const settings = await getGlobalServiceAvailability();
return settings.apiGlobal;
}
export interface ReminderThresholds {
lateMinutes: number;
missedMinutes: number;
}
export async function getReminderThresholds(): Promise<ReminderThresholds> {
try {
const settings = await prisma.appSettings.findUnique({
where: { id: "singleton" },
select: {
reminderLateMinutes: true,
reminderMissedMinutes: true,
},
});
return {
lateMinutes: settings?.reminderLateMinutes ?? 120,
missedMinutes: settings?.reminderMissedMinutes ?? 240,
};
} catch {
getEvent()?.addWarning(
"Failed to load reminder thresholds, using defaults",
);
return { lateMinutes: 120, missedMinutes: 240 };
}
}