feat: add settings service

This commit is contained in:
rajun 2026-10-27 16:28:59 +05:30
parent ed4dd44a69
commit 7b6aecd385

17
app/services/settings.ts Normal file
View File

@ -0,0 +1,17 @@
import { pb } from '~/services/pocketbase';
import { DEFAULT_SETTINGS, SETTINGS_COLLECTION } from '~/data/settings/constants';
import type { AppSettings, SettingKey } from '~/types/settings';
const settings = () => pb.collection<AppSettings & { id: string }>(SETTINGS_COLLECTION);
// A single settings record, seeded by the migration; defaults apply if it is missing
export async function getSettings(): Promise<AppSettings> {
const { items } = await settings().getList(1, 1);
return items[0] ?? DEFAULT_SETTINGS;
}
export async function updateSetting(key: SettingKey, value: boolean) {
const current = await getSettings();
if (!current.id) throw new Error('Settings are not set up yet');
return settings().update(current.id, { [key]: value });
}