refactor(18): IN-01/IN-02 reuse fetched row for GET timezone fallback

The GET /config/timezone handler SELECTed app_config then, on the unset
path, called getHouseholdTimezone(db) which re-issued the identical
SELECT before falling back (IN-01). The fallback decision also lived in
two places (IN-02). Route the handler through the centralized
resolveHouseholdTimezone(row?.value) added for WR-01: no redundant
round-trip, single source for the D-06 policy. Behavior unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lucas Berger
2026-06-15 07:38:45 -04:00
co-authored by Claude Opus 4.8
parent d168da71cf
commit 692fe2ad9a
+4 -4
View File
@@ -27,7 +27,7 @@ import { eq, sql } from 'drizzle-orm';
import { db } from '../db/client.js'; import { db } from '../db/client.js';
import { users, memberCredentials, calendars, appConfig } from '../db/schema.js'; import { users, memberCredentials, calendars, appConfig } from '../db/schema.js';
import { requireAdmin } from '../lib/requireAdmin.js'; import { requireAdmin } from '../lib/requireAdmin.js';
import { isValidIanaTimezone, getHouseholdTimezone } from '../lib/householdTimezone.js'; import { isValidIanaTimezone, resolveHouseholdTimezone } from '../lib/householdTimezone.js';
import { import {
validateEncryptAndStoreCredential, validateEncryptAndStoreCredential,
CredentialValidationError, CredentialValidationError,
@@ -205,9 +205,9 @@ adminRouter.get('/config/timezone', async (c) => {
.limit(1); .limit(1);
const isExplicitlySet = row?.value != null; const isExplicitlySet = row?.value != null;
const timezone = isExplicitlySet // IN-01/IN-02: reuse the row we just SELECTed and let the centralized accessor apply
? (row.value as string) // the D-06 fallback — no second app_config round-trip, single source for the policy.
: await getHouseholdTimezone(db); const timezone = resolveHouseholdTimezone(row?.value ?? null);
return c.json({ timezone, isExplicitlySet }); return c.json({ timezone, isExplicitlySet });
}); });