Implements the full ADMIN → ORGANISMO_OPERADOR → OPERATOR permission hierarchy with scope-filtered data access across all backend services. Adds organismos operadores management (ADMIN only) and a new Histórico page for viewing per-meter reading history with chart, consumption stats, and CSV export. Key changes: - Backend: 3-level scope filtering on all services (meters, readings, projects, users) - Backend: Protect GET /meters routes with authenticateToken for role-based filtering - Backend: Pass requestingUser to reading service for scoped meter readings - Frontend: New HistoricoPage with meter selector, AreaChart, paginated table - Frontend: Consumption cards (Actual, Pasado, Diferencial) above date filters - Frontend: Meter search by name, serial, location, CESPT account, cadastral key - Frontend: OrganismosPage, updated Sidebar with 3-level visibility - SQL migrations for organismos_operadores table and FK columns Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
12 lines
584 B
SQL
12 lines
584 B
SQL
-- Add new fields to users table
|
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS phone VARCHAR(20);
|
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS street VARCHAR(255);
|
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS city VARCHAR(100);
|
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS state VARCHAR(100);
|
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS zip_code VARCHAR(10);
|
|
|
|
-- Add new fields to meters table
|
|
ALTER TABLE meters ADD COLUMN IF NOT EXISTS address TEXT;
|
|
ALTER TABLE meters ADD COLUMN IF NOT EXISTS cespt_account VARCHAR(50);
|
|
ALTER TABLE meters ADD COLUMN IF NOT EXISTS cadastral_key VARCHAR(50);
|