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