feat: Display Settings UI + Company Category/Type sync

- Add /admin/display-settings page with Kiosk and Mobile sections
- Company category checkbox filter + excluded companies searchable multi-select
- New DB tables: company_categories, company_types (migration 064)
- Sync COMPANY_CATEGORIES via CompanyCategories entity (id/name/isActive)
- Sync COMPANY_TYPES via Companies.companyType picklist
- Add to EntityType, ENTITY_DEPENDENCIES, sync-helpers, entity-mapper, entity-sync
- New API routes: /api/admin/display-settings (GET/POST), /api/data/company-categories, /api/data/companies-list
- Update all 4 routes (kiosk/stats, kiosk/activity, mobile/tickets, mobile/dashboard)
  to filter by kiosk_settings company_category_ids + excluded_company_ids
- Add Display Settings nav link (SlidersHorizontal icon) to Admin menu
- Seed kiosk_settings: kiosk_company_category_ids=1, mobile_company_category_ids=1
This commit is contained in:
lorentz 2026-04-06 09:03:19 -04:00
parent 89dbe6155b
commit 07067bef19
16 changed files with 847 additions and 85 deletions

View file

@ -0,0 +1,45 @@
-- Migration 063: Relax tickets company_id and resource FK constraints
-- Both were causing ticket sync to fail with DATABASE_CONSTRAINT_ERROR.
--
-- Root causes:
-- 1. tickets_company_id_fkey — strict, not deferrable, ON DELETE CASCADE.
-- Tickets whose company_id references a company not yet in the local
-- companies table fail on upsert.
-- 2. tickets_assigned_resource_id_fkey — was relaxed in migration 008 but
-- got re-created as strict (condeferrable=f) by a subsequent migration.
--
-- Fix: make both constraints deferrable INITIALLY DEFERRED with ON DELETE SET NULL.
-- ── company_id ──────────────────────────────────────────────────────────────
ALTER TABLE tickets DROP CONSTRAINT IF EXISTS tickets_company_id_fkey;
ALTER TABLE tickets ALTER COLUMN company_id DROP NOT NULL;
ALTER TABLE tickets
ADD CONSTRAINT tickets_company_id_fkey
FOREIGN KEY (company_id) REFERENCES companies(id)
ON DELETE SET NULL
DEFERRABLE INITIALLY DEFERRED;
-- ── assigned_resource_id (re-apply in case it was reset) ────────────────────
ALTER TABLE tickets DROP CONSTRAINT IF EXISTS tickets_assigned_resource_id_fkey;
ALTER TABLE tickets ALTER COLUMN assigned_resource_id DROP NOT NULL;
ALTER TABLE tickets
ADD CONSTRAINT tickets_assigned_resource_id_fkey
FOREIGN KEY (assigned_resource_id) REFERENCES resources(id)
ON DELETE SET NULL
DEFERRABLE INITIALLY DEFERRED;
-- ── first_response resource IDs ─────────────────────────────────────────────
ALTER TABLE tickets DROP CONSTRAINT IF EXISTS tickets_first_response_assigned_resource_id_fkey;
ALTER TABLE tickets DROP CONSTRAINT IF EXISTS tickets_first_response_initiating_resource_id_fkey;
ALTER TABLE tickets
ADD CONSTRAINT tickets_first_response_assigned_resource_id_fkey
FOREIGN KEY (first_response_assigned_resource_id) REFERENCES resources(id)
ON DELETE SET NULL
DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE tickets
ADD CONSTRAINT tickets_first_response_initiating_resource_id_fkey
FOREIGN KEY (first_response_initiating_resource_id) REFERENCES resources(id)
ON DELETE SET NULL
DEFERRABLE INITIALLY DEFERRED;

View file

@ -0,0 +1,31 @@
-- Company Categories picklist table (synced from Autotask Companies.companyCategoryID field)
CREATE TABLE IF NOT EXISTS company_categories (
value INTEGER PRIMARY KEY,
label VARCHAR(200) NOT NULL,
is_active BOOLEAN DEFAULT true,
sort_order INTEGER DEFAULT 0,
synced_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Company Types picklist table (synced from Autotask Companies.companyType field)
CREATE TABLE IF NOT EXISTS company_types (
value INTEGER PRIMARY KEY,
label VARCHAR(200) NOT NULL,
is_active BOOLEAN DEFAULT true,
sort_order INTEGER DEFAULT 0,
synced_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_company_categories_active ON company_categories(is_active);
CREATE INDEX IF NOT EXISTS idx_company_types_active ON company_types(is_active);
-- Seed new display settings keys into kiosk_settings
INSERT INTO kiosk_settings (setting_key, setting_value, description) VALUES
('kiosk_company_category_ids', '1', 'Comma-separated company category IDs to include in kiosk (default: 1=Recurring Revenue Customer)'),
('mobile_company_category_ids', '1', 'Comma-separated company category IDs to include in mobile (default: 1=Recurring Revenue Customer)'),
('mobile_excluded_company_ids', '', 'Comma-separated company IDs to exclude from mobile dashboard')
ON CONFLICT (setting_key) DO NOTHING;