Skip to content

feat(waiter-calls): live waiting timer and attention times in analytics - #255

Merged
juancodedev merged 2 commits into
mainfrom
feat/waiter-call-timer-stats
Nov 2, 2026
Merged

juancodedev merged 2 commits into
mainfrom
feat/waiter-call-timer-stats

Conversation

@juancodedev

Copy link
Copy Markdown
Owner

Summary

Two additions to waiter calls.

1. Live waiting timer

On /waiter and in the admin bell, each pending call now shows Esperando mm:ss, ticking every second. Before, the list said "recién" or "hace N min" and refreshed every 15 s.

  • The timer is a <time role="timer"> element; its datetime is the time the call was created.
  • Its color shows the urgency: gray under 2 min, amber from 2 min, red from 4 min. Calls expire at 5 min.

2. Attention times in Analíticas

A new "Llamados de mesa" panel uses the same local and period filter as the rest of the page. It shows:

  • Average, median and slowest time from the call to "Atendido".
  • Attended calls out of the total.
  • Calls that expired without attention.
  • A "Por mesero" table with each staff user's attended calls, average and slowest time.

New RPC get_waiter_call_stats(p_tenant_id, p_from, p_to) in database/create-waiter-call-stats.sql:

  • It is SECURITY INVOKER, like get_analytics. The caller's RLS (waiter_calls_staff_select) still scopes the rows.
  • Role checks match get_analytics: only tenant_admin (own local) and super_admin (any local, or NULL for all locals) may call it.
  • Wait time is resolved_at - created_at of attended calls. resolved_at and resolved_by are already stamped server-side by the existing trigger, so the data is there for past calls too.
  • Expired also counts pending calls already past expires_at that no newer call has swept yet.
  • It adds the index waiter_calls_tenant_created_idx (tenant_id, created_at).
  • Staff names come from the existing /api/admin/users, because admin_users is not readable from the browser. A user who is unknown or was deleted shows as "Sin identificar". If the names fail to load, the times still show.

Deploy

Run database/create-waiter-call-stats.sql in the Supabase SQL Editor. It has no psql meta-commands and can be re-run.
Rollback: database/rollback-create-waiter-call-stats.sql (calls are kept).
Until the SQL is applied, the panel shows "No se pudieron cargar los llamados de mesa." and the rest of Analíticas keeps working.

Verification

  • Tests written first, each failing before its change:
    • the timer label and urgency, and the 1 s clock in useWaiterCalls
    • waiterCallStats.test.jsx (7 tests)
    • Analytics passes the local and period to the panel
    • the static contract of the migration
  • Postgres 16 lab:
    • The migration applies twice.
    • Metrics match the fixture: 30, 90 and 240 s give avg 120, median 90, max 240. Pending calls past expires_at count as expired, and calls outside the range are excluded.
    • Per-staff groups are correct, and an attended call with no resolved_by gets staff_id null.
    • Tenant admin asking for another local or for all locals: forbidden. Waiter: forbidden. Anon: permission denied. Inverted range: invalid_range. Super admin: all locals or a single one.
    • Rollback removes the function and the index and keeps the 9 calls.
  • npm run test:run: 622 passed; npm run lint clean; npm run build OK.

Risk: item 2 (a new RPC callable by authenticated; its role and tenant checks were proven in the lab).

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tappmesa Building Building Preview Nov 2, 2026 9:24pm UTC

@juancodedev
juancodedev merged commit 69878ef into main Nov 2, 2026
6 checks passed

This branch was successfully deployed

1 active deployment
Preview — 47484629 Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant