Actualizar server.js
This commit is contained in:
46
server.js
46
server.js
@@ -1812,7 +1812,7 @@ app.post("/providers/credentials", authMiddleware, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 📥 RECEPCIÓN DE SERVICIOS (EMBUDO INTELIGENTE DEFINITIVO)
|
// 📥 RECEPCIÓN DE SERVICIOS (EL DETECTOR DEFINITIVO POR DESCRIPCIÓN)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -1832,7 +1832,7 @@ app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
|||||||
|
|
||||||
for (const svc of services) {
|
for (const svc of services) {
|
||||||
|
|
||||||
// 1. EXTRAER REFERENCIA A PRUEBA DE BOMBAS (Incluye "SERVICIO" de HomeServe)
|
// 1. EXTRAER REFERENCIA (Soportando "SERVICIO" de HomeServe)
|
||||||
const ref = svc['service_ref']
|
const ref = svc['service_ref']
|
||||||
|| svc['SERVICIO']
|
|| svc['SERVICIO']
|
||||||
|| svc['Referencia']
|
|| svc['Referencia']
|
||||||
@@ -1842,31 +1842,34 @@ app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
|||||||
|| (svc.raw_data && (svc.raw_data['SERVICIO'] || svc.raw_data['Referencia'] || svc.raw_data['Nº Siniestro'] || svc.raw_data['Expediente'] || svc.raw_data['expediente']));
|
|| (svc.raw_data && (svc.raw_data['SERVICIO'] || svc.raw_data['Referencia'] || svc.raw_data['Nº Siniestro'] || svc.raw_data['Expediente'] || svc.raw_data['expediente']));
|
||||||
|
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
console.log("⚠️ Se omitió un servicio por no encontrar el número de referencia.");
|
console.log("⚠️ Se omitió un servicio por no encontrar referencia.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. DETECTOR DE URGENCIAS (APLASTAMIENTO TOTAL - CERO FALSOS POSITIVOS)
|
// 🔥 2. EL DETECTOR BRILLANTE (Solo busca en Descripción y Estados) 🔥
|
||||||
let esUrgente = false;
|
let esUrgente = false;
|
||||||
|
|
||||||
// Juntamos todos los valores del objeto en un solo string
|
const camposABuscar = [
|
||||||
const textoPlano = JSON.stringify(svc).toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
svc['ACTUALMENTE EN'],
|
||||||
|
svc['Estado'],
|
||||||
|
svc['ESTADO'],
|
||||||
|
svc['Descripción'],
|
||||||
|
svc['DESCRIPCION'],
|
||||||
|
svc['Urgente'],
|
||||||
|
svc['URGENTE'],
|
||||||
|
svc.raw_data ? svc.raw_data['Descripción'] : null,
|
||||||
|
svc.raw_data ? svc.raw_data['DESCRIPCION'] : null,
|
||||||
|
svc.raw_data ? svc.raw_data['ACTUALMENTE EN'] : null
|
||||||
|
];
|
||||||
|
|
||||||
// Caso HomeServe: frases mágicas exactas (cero falsos positivos)
|
for (const texto of camposABuscar) {
|
||||||
if (
|
if (!texto) continue;
|
||||||
textoPlano.includes('atencion presencial urgencias') ||
|
// Lo pasamos a minúsculas y le quitamos los acentos
|
||||||
textoPlano.includes('atencion de la urgencia')
|
const val = String(texto).toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||||
) {
|
|
||||||
|
if (val.includes('urgencia') || val.includes('urgente')) {
|
||||||
esUrgente = true;
|
esUrgente = true;
|
||||||
} else {
|
break; // Si lo encuentra, dejamos de buscar
|
||||||
// Caso Multiasistencia u otros: si la columna se llama Urgencia/Urgent y el valor es "si" o "true"
|
|
||||||
for (const key in svc) {
|
|
||||||
const col = String(key).toLowerCase();
|
|
||||||
const val = String(svc[key]).toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
||||||
if ((col.includes('urgent') || col === 'urgencia') && (val === 'si' || val === 'true' || val === 'si')) {
|
|
||||||
esUrgente = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1890,7 +1893,8 @@ app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
|||||||
if (esUrgente && guildId && autoDispatchEnabled && (autoStatus === 'manual' || autoStatus === 'pending')) {
|
if (esUrgente && guildId && autoDispatchEnabled && (autoStatus === 'manual' || autoStatus === 'pending')) {
|
||||||
console.log(`⚡ [AUTO-DISPATCH] Lanzando urgencia ${ref} de ${provider} a la bolsa...`);
|
console.log(`⚡ [AUTO-DISPATCH] Lanzando urgencia ${ref} de ${provider} a la bolsa...`);
|
||||||
|
|
||||||
const cpMatch = textoPlano.match(/\b\d{5}\b/);
|
const todoElTexto = JSON.stringify(svc).toLowerCase();
|
||||||
|
const cpMatch = todoElTexto.match(/\b\d{5}\b/);
|
||||||
const cpFinal = cpMatch ? cpMatch[0] : "00000";
|
const cpFinal = cpMatch ? cpMatch[0] : "00000";
|
||||||
|
|
||||||
const port = process.env.PORT || 3000;
|
const port = process.env.PORT || 3000;
|
||||||
|
|||||||
Reference in New Issue
Block a user