Actualizar server.js

This commit is contained in:
2026-04-03 15:38:45 +00:00
parent a8ab910a27
commit bcd96a6b56

View File

@@ -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; let activeSubscription = null;
if (cleanPhoneSearch.length >= 9) { if (cleanPhoneSearch.length >= 9) {
const subQ = await pool.query(` 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 p.name as plan_name, p.bricos_limit, p.urgencies_limit
FROM protection_subscriptions s FROM protection_subscriptions s
JOIN protection_plans p ON s.plan_id = p.id 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 ORDER BY s.created_at DESC LIMIT 1
`, [ownerId, `%${cleanPhoneSearch}%`]); `, [ownerId, `%${cleanPhoneSearch}%`]);
@@ -4916,7 +4916,7 @@ app.get("/public/portal/:token/protection", async (req, res) => {
const client = clientQ.rows[0]; const client = clientQ.rows[0];
const ownerId = client.owner_id; 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, ""); let cleanPhone = String(client.phone || "").replace(/[^0-9]/g, "");
if (cleanPhone.length > 9) cleanPhone = cleanPhone.slice(-9); 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 SELECT s.status, p.name as plan_name
FROM protection_subscriptions s FROM protection_subscriptions s
JOIN protection_plans p ON s.plan_id = p.id 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 ORDER BY s.created_at DESC LIMIT 1
`, [ownerId, `%${cleanPhone}%`]); `, [ownerId, `%${cleanPhone}%`]);