diff --git a/server.js b/server.js index ef9b593..7da97e5 100644 --- a/server.js +++ b/server.js @@ -1700,7 +1700,7 @@ app.get("/public/portal/:token", async (req, res) => { })); } - // 🚀 5. NUEVO: BUSCAR SI TIENE PLAN DE PROTECCIÓN ACTIVO + // 🚀 5. NUEVO: BUSCAR SI TIENE PLAN DE PROTECCIÓN ACTIVO let activeSubscription = null; if (cleanPhoneSearch.length >= 9) { const subQ = await pool.query(` @@ -1708,7 +1708,7 @@ app.get("/public/portal/:token", async (req, res) => { p.name as plan_name, p.bricos_limit, p.urgencies_limit FROM protection_subscriptions s JOIN protection_plans p ON s.plan_id = p.id - WHERE s.company_id = $1 AND s.client_phone LIKE $2 AND s.status != 'expirado' + WHERE s.company_id = $1 AND s.client_phone LIKE $2 AND s.status = 'activo' AND s.payment_status = 'pagado' ORDER BY s.created_at DESC LIMIT 1 `, [ownerId, `%${cleanPhoneSearch}%`]); @@ -4916,7 +4916,7 @@ app.get("/public/portal/:token/protection", async (req, res) => { const client = clientQ.rows[0]; const ownerId = client.owner_id; - // Comprobar si el cliente YA tiene un plan activo + // Comprobar si el cliente YA tiene un plan activo (Solo si está pagado y activo) let cleanPhone = String(client.phone || "").replace(/[^0-9]/g, ""); if (cleanPhone.length > 9) cleanPhone = cleanPhone.slice(-9); @@ -4924,7 +4924,7 @@ app.get("/public/portal/:token/protection", async (req, res) => { SELECT s.status, p.name as plan_name FROM protection_subscriptions s JOIN protection_plans p ON s.plan_id = p.id - WHERE s.company_id = $1 AND s.client_phone LIKE $2 AND s.status != 'expirado' + WHERE s.company_id = $1 AND s.client_phone LIKE $2 AND s.status = 'activo' AND s.payment_status = 'pagado' ORDER BY s.created_at DESC LIMIT 1 `, [ownerId, `%${cleanPhone}%`]);