migrate from hono
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { todayInTz, resolveTz } from '@shared/timezone';
|
||||
import { famMeta } from './fam';
|
||||
|
||||
function resolveServerTz(tz?: string): string {
|
||||
return resolveTz(tz || 'auto');
|
||||
}
|
||||
|
||||
export async function getSettings(pb: any, famId: string) {
|
||||
const list = await pb.collection('settings').getFullList({ filter: `famId = '${famId}'` });
|
||||
const s = list?.[0] || {};
|
||||
return { simulateEow: !!s.simulateEow, webhookUrl: s.webhookUrl || '' };
|
||||
}
|
||||
|
||||
export async function updateSettings(pb: any, famId: string, data: Record<string, unknown>) {
|
||||
const list = await pb.collection('settings').getFullList({ filter: `famId = '${famId}'` });
|
||||
const existing = list?.[0];
|
||||
const patch: Record<string, unknown> = {};
|
||||
if (data.simulateEow !== undefined) patch.simulateEow = !!data.simulateEow;
|
||||
if (data.webhookUrl !== undefined) patch.webhookUrl = String(data.webhookUrl);
|
||||
let s;
|
||||
if (existing) {
|
||||
s = Object.keys(patch).length ? await pb.collection('settings').update(existing.id, patch) : existing;
|
||||
} else {
|
||||
s = await pb.collection('settings').create({ famId, ...patch });
|
||||
}
|
||||
return { simulateEow: !!s.simulateEow, webhookUrl: s.webhookUrl || '' };
|
||||
}
|
||||
Reference in New Issue
Block a user