ar-test/app/services/settings.ts
2026-10-27 16:28:59 +05:30

18 lines
770 B
TypeScript

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 });
}