This commit is contained in:
2026-05-26 23:30:22 +12:00
parent 135a5a3b83
commit 91b22c6d60
27 changed files with 2401 additions and 88 deletions
+51
View File
@@ -303,6 +303,57 @@ async def set_kv(key: str, value: Any) -> bool:
return True
async def get_submission_journey(email: str) -> dict | None:
"""Return the most recent submission_journeys row for the given email, or
None when no journey was promoted (or DB is off). The table is owned by
the SvelteKit app — see src/routes/api/track/promote — but the mail-api
reads it here so the owner dashboard's enquiry view can render it
alongside the booking record."""
pool = await get_pool()
if pool is None:
return None
normalized = (email or "").strip().lower()
if not normalized:
return None
try:
async with pool.acquire() as conn:
row = await conn.fetchrow(
"""
select id, anon_id, events, client_events, created_at
from submission_journeys
where email = $1
order by created_at desc
limit 1
""",
normalized,
)
except Exception as exc:
# Table may not exist yet in environments where the new init script
# hasn't run. Don't break the enquiry view over it.
logger.warning("submission_journeys read failed: %s", exc)
return None
if not row:
return None
def _parse(value: Any) -> Any:
if isinstance(value, (list, dict)):
return value
if isinstance(value, (bytes, bytearray)):
value = value.decode("utf-8")
try:
return json.loads(value) if value else []
except Exception:
return []
return {
"id": row["id"],
"anonId": row["anon_id"],
"events": _parse(row["events"]),
"clientEvents": _parse(row["client_events"]),
"createdAt": row["created_at"].isoformat() if row["created_at"] else None,
}
async def has_any_value() -> bool:
"""Return True if admin_kv already has any rows. Used to decide whether
to seed from JSON files on first boot."""