v4.0.0.3
This commit is contained in:
@@ -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."""
|
||||
|
||||
+6
-1
@@ -3165,7 +3165,12 @@ async def owner_client_enquiry(request: Request):
|
||||
"referrer": "",
|
||||
"page": "",
|
||||
}
|
||||
return {"ok": True, "enquiry": enquiry}
|
||||
# Journey is populated by the SvelteKit /api/track/promote endpoint when
|
||||
# the visitor submits the booking form. None means we never recorded a
|
||||
# journey for this email (legacy submission, ad-blocker that also blocked
|
||||
# /api/track, or DB-less local dev).
|
||||
journey = await admin_db.get_submission_journey(email)
|
||||
return {"ok": True, "enquiry": enquiry, "journey": journey}
|
||||
|
||||
|
||||
@app.get("/owner/activity")
|
||||
|
||||
Reference in New Issue
Block a user