Actualizar server.js
This commit is contained in:
15
server.js
15
server.js
@@ -405,6 +405,7 @@ app.get("/public/portal/:token", async (req, res) => {
|
||||
// 3. Obtenemos los servicios.
|
||||
// AHORA BUSCAMOS POR client_id. Si el client_id es nulo (expedientes viejos), buscamos por teléfono en el JSON.
|
||||
const cleanPhoneToMatch = String(client.phone || "").replace(/\D/g, "").slice(-9);
|
||||
const requestedServiceId = req.query.service || null; // <-- Capturamos el ID del enlace si existe
|
||||
|
||||
const qServices = await pool.query(`
|
||||
SELECT
|
||||
@@ -419,16 +420,14 @@ app.get("/public/portal/:token", async (req, res) => {
|
||||
WHERE s.owner_id = $1
|
||||
AND s.provider != 'SYSTEM_BLOCK'
|
||||
AND (
|
||||
s.client_id = $2
|
||||
OR
|
||||
(s.client_id IS NULL AND REPLACE(s.raw_data->>'Teléfono', ' ', '') LIKE $3)
|
||||
OR
|
||||
(s.client_id IS NULL AND REPLACE(s.raw_data->>'TELEFONO', ' ', '') LIKE $3)
|
||||
OR
|
||||
(s.client_id IS NULL AND REPLACE(s.raw_data->>'TELEFONOS', ' ', '') LIKE $3)
|
||||
s.id::text = $4 -- <-- LA MAGIA: Forzamos a que traiga el expediente del enlace
|
||||
OR s.client_id = $2
|
||||
OR (s.client_id IS NULL AND REPLACE(s.raw_data->>'Teléfono', ' ', '') LIKE $3)
|
||||
OR (s.client_id IS NULL AND REPLACE(s.raw_data->>'TELEFONO', ' ', '') LIKE $3)
|
||||
OR (s.client_id IS NULL AND REPLACE(s.raw_data->>'TELEFONOS', ' ', '') LIKE $3)
|
||||
)
|
||||
ORDER BY s.created_at DESC
|
||||
`, [ownerId, clientId, `%${cleanPhoneToMatch}%`]);
|
||||
`, [ownerId, clientId, `%${cleanPhoneToMatch}%`, requestedServiceId]);
|
||||
|
||||
const formattedServices = qServices.rows.map(s => {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user