Actualizar server.js

This commit is contained in:
2026-03-04 08:49:39 +00:00
parent 8c107e0339
commit 47976642da

View File

@@ -405,9 +405,8 @@ app.get("/public/portal/:token", async (req, res) => {
if (phoneMatch.length < 8) phoneMatch = "NO_VALIDO_123";
// 4. BÚSQUEDA FUERZA BRUTA: Limpiamos los espacios de la BD antes de buscar
const qServices = await pool.query(`
qServices = await pool.query(`
SELECT s.id, s.service_ref, s.is_urgent, s.raw_data, s.created_at,
NULL as client_id,
st.name as real_status_name, st.is_final as is_status_final,
u.full_name as worker_name, u.phone as worker_phone
FROM scraped_services s
@@ -415,10 +414,9 @@ app.get("/public/portal/:token", async (req, res) => {
LEFT JOIN service_statuses st ON st.id::text = (s.raw_data->>'status_operativo')::text
WHERE s.owner_id = $1 AND s.provider != 'SYSTEM_BLOCK'
AND (
REGEXP_REPLACE(s.raw_data->>'Teléfono', '\\D', '', 'g') LIKE $2
OR REGEXP_REPLACE(s.raw_data->>'TELEFONO', '\\D', '', 'g') LIKE $2
OR REGEXP_REPLACE(s.raw_data->>'TELEFONOS', '\\D', '', 'g') LIKE $2
OR REGEXP_REPLACE(s.raw_data::text, '\\D', '', 'g') LIKE $2
COALESCE(REPLACE(s.raw_data->>'Teléfono', ' ', ''), '') LIKE $2
OR COALESCE(REPLACE(s.raw_data->>'TELEFONO', ' ', ''), '') LIKE $2
OR COALESCE(REPLACE(s.raw_data->>'TELEFONOS', ' ', ''), '') LIKE $2
)
ORDER BY s.created_at DESC
`, [ownerId, `%${phoneMatch}%`]);