Add editable display title (was hardcoded to VITE_HOTEL_NAME)

New `config` table + routes/config.js: GET /api/public/config (no auth,
Display.tsx needs it with no session) and PUT /api/admin/config (authed +
'settings' cap). A blank title clears the override and falls back to the
build-time VITE_HOTEL_NAME, so an unconfigured install still shows
something sensible. Admin.tsx gets a "Display title" field above the
existing status card.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-08-25 12:53:09 +00:00
parent 0a6eec65e7
commit 7f3ff4495c
8 changed files with 151 additions and 10 deletions

View file

@ -48,8 +48,18 @@ export async function initDb() {
sunset TIMESTAMPTZ,
fetched_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
`)
-- User-editable display settings (currently just display_title). Separate from
-- the status table (fetch bookkeeping, not user-facing) -- same KV shape as
-- tasks' config table. A missing/null display_title falls back to
-- VITE_HOTEL_NAME at the frontend (see routes/config.js), so an unconfigured
-- app still shows something sensible without requiring a rebuild.
CREATE TABLE IF NOT EXISTS config (
key TEXT PRIMARY KEY,
value JSONB NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
`)
}
export async function getStatus() {
@ -64,3 +74,16 @@ export async function setStatus(key, value) {
[key, JSON.stringify(value)]
)
}
export async function getConfig() {
const { rows } = await pool.query('SELECT key, value FROM config')
return Object.fromEntries(rows.map(r => [r.key, r.value]))
}
export async function setConfigValue(key, value) {
await pool.query(
`INSERT INTO config (key, value, updated_at) VALUES ($1, $2, NOW())
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = NOW()`,
[key, JSON.stringify(value)]
)
}