Actualizar server.js

This commit is contained in:
2026-04-02 19:43:03 +00:00
parent e1f53a3fe0
commit 233c11c6b8

View File

@@ -296,6 +296,60 @@ async function autoUpdateDB() {
created_at TIMESTAMP DEFAULT NOW()
);
-- ==========================================
-- 🛡️ MÓDULO SAAS: PLANES DE PROTECCIÓN
-- ==========================================
CREATE TABLE IF NOT EXISTS protection_config (
company_id INT PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
name TEXT,
email TEXT,
phone TEXT,
auto_renew BOOLEAN DEFAULT TRUE,
pre_notice BOOLEAN DEFAULT TRUE,
billing_method TEXT DEFAULT 'stripe',
contract_text TEXT,
updated_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS protection_plans (
id SERIAL PRIMARY KEY,
company_id INT REFERENCES users(id) ON DELETE CASCADE,
name TEXT NOT NULL,
type TEXT NOT NULL,
price DECIMAL(10,2) DEFAULT 0.00,
renewal_price DECIMAL(10,2) DEFAULT 0.00,
urgencies_limit INT DEFAULT 0,
bricos_limit INT DEFAULT 0,
coverages TEXT,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS protection_subscriptions (
id SERIAL PRIMARY KEY,
company_id INT REFERENCES users(id) ON DELETE CASCADE,
plan_id INT REFERENCES protection_plans(id) ON DELETE RESTRICT,
client_name TEXT NOT NULL,
client_dni TEXT,
client_phone TEXT,
payment_status TEXT DEFAULT 'pagado',
status TEXT DEFAULT 'activo',
custom_discount INT DEFAULT 0,
bricos_used INT DEFAULT 0,
urgencies_used INT DEFAULT 0,
renewal_date DATE,
contract_pdf_url TEXT,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS protection_activity (
id SERIAL PRIMARY KEY,
company_id INT REFERENCES users(id) ON DELETE CASCADE,
type TEXT NOT NULL,
description TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- 💬 CHAT Y NOTAS INTERNAS
CREATE TABLE IF NOT EXISTS service_communications (
id SERIAL PRIMARY KEY,