+
-if (!DATABASE_URL || !JWT_SECRET) {
- console.error("❌ ERROR FATAL: Faltan variables de entorno");
- process.exit(1);
-}
+
+
-const {
- DATABASE_URL,
- JWT_SECRET,
- EVOLUTION_BASE_URL,
- EVOLUTION_API_KEY,
- EVOLUTION_INSTANCE,
-} = process.env;
+
+
+
+ + Servicios Activos +
+Gestiona las reparaciones y sus estados.
+
+
+
+
+
+ | Fecha | +Cliente / Dirección | +Detalle | +Estado | ++ |
|---|---|---|---|---|
| Cargando servicios... | ||||
+
-const pool = new Pool({
- connectionString: DATABASE_URL,
- ssl: false
-});
+
- // 3. TABLA SERVICIOS (Con FK a status)
- await client.query(`
- CREATE TABLE IF NOT EXISTS services (
- id SERIAL PRIMARY KEY,
- owner_id INT REFERENCES users(id) ON DELETE CASCADE,
- client_id INT REFERENCES clients(id) ON DELETE SET NULL,
- status_id INT REFERENCES service_statuses(id) ON DELETE SET NULL, -- NUEVO: ID del estado
- title TEXT,
- description TEXT,
- contact_phone TEXT NOT NULL,
- contact_name TEXT NOT NULL,
- address TEXT NOT NULL,
- email TEXT,
- scheduled_date DATE DEFAULT CURRENT_DATE,
- scheduled_time TIME DEFAULT CURRENT_TIME,
- duration_minutes INT DEFAULT 30,
- is_urgent BOOLEAN DEFAULT FALSE,
- is_company BOOLEAN DEFAULT FALSE,
- company_id INT REFERENCES companies(id) ON DELETE SET NULL,
- company_ref TEXT,
- internal_notes TEXT,
- client_notes TEXT,
- closed_at TIMESTAMP,
- created_at TIMESTAMP DEFAULT NOW()
- );
- `);
+
- // 4. NUEVO: TABLA LOGS DE ESTADOS (TRAZABILIDAD)
- await client.query(`
- CREATE TABLE IF NOT EXISTS service_logs (
- id SERIAL PRIMARY KEY,
- service_id INT REFERENCES services(id) ON DELETE CASCADE,
- user_id INT REFERENCES users(id) ON DELETE SET NULL, -- Quién hizo el cambio
- old_status_id INT REFERENCES service_statuses(id),
- new_status_id INT REFERENCES service_statuses(id),
- comment TEXT, -- Comentario del cambio (ej: "Cliente no estaba")
- created_at TIMESTAMP DEFAULT NOW()
- );
- `);
+