Actualizar server.js
This commit is contained in:
22
server.js
22
server.js
@@ -1412,16 +1412,34 @@ app.get("/public/portal/:token", async (req, res) => {
|
|||||||
client_name: b.client_name,
|
client_name: b.client_name,
|
||||||
client_phone: b.client_phone,
|
client_phone: b.client_phone,
|
||||||
client_address: b.client_address,
|
client_address: b.client_address,
|
||||||
status: b.status // 🛑 FIX: Faltaba enviar el estado al móvil
|
status: b.status
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🚀 5. NUEVO: BUSCAR SI TIENE PLAN DE PROTECCIÓN ACTIVO
|
||||||
|
let activeSubscription = null;
|
||||||
|
if (cleanPhoneSearch.length >= 9) {
|
||||||
|
const subQ = await pool.query(`
|
||||||
|
SELECT s.status, s.payment_status, s.bricos_used, s.urgencies_used, s.renewal_date,
|
||||||
|
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'
|
||||||
|
ORDER BY s.created_at DESC LIMIT 1
|
||||||
|
`, [ownerId, `%${cleanPhoneSearch}%`]);
|
||||||
|
|
||||||
|
if (subQ.rowCount > 0) {
|
||||||
|
activeSubscription = subQ.rows[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
ok: true,
|
ok: true,
|
||||||
client: { name: client.full_name },
|
client: { name: client.full_name },
|
||||||
company,
|
company,
|
||||||
services: formattedServices,
|
services: formattedServices,
|
||||||
quotes: formattedQuotes
|
quotes: formattedQuotes,
|
||||||
|
subscription: activeSubscription // <-- 🟢 Lo pasamos al frontend del cliente
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user