diff --git a/robot.js b/robot.js index 07c4012..9638f7b 100644 --- a/robot.js +++ b/robot.js @@ -198,13 +198,13 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) { const expedientes = Array.from(todosExpedientes); console.log(`\n✅ [Multi] TOTAL EXPEDIENTES LEÍDOS EN WEB: ${expedientes.length}`); - console.log(`📋 REFERENCIAS LEÍDAS:`, expedientes.join(', ')); - if (expedientes.length > 0) { + // 🛑 NUEVO SEGURO DE VIDA: Si lee menos de 5, desconfiamos de la web y NO archivamos nada, por si es un error puntual. + if (expedientes.length > 5 || paginaActual === 1) { console.log(`🧹 Llamando a la escoba (syncAndArchive) con ${expedientes.length} refs...`); await syncAndArchive(ownerId, 'multiasistencia', expedientes); } else { - console.log("⚠️ [Multi] ¡CUIDADO! Se han detectado 0 expedientes. ABORTANDO LA ESCOBA para no cerrar nada."); + console.log("⚠️ [Multi] Pocos expedientes detectados. ABORTANDO ARCHIVADO DE SEGURIDAD."); } for (const ref of expedientes) { @@ -460,7 +460,8 @@ async function syncAndArchive(ownerId, provider, currentWebRefs) { const statusQ = await client.query("SELECT id FROM service_statuses WHERE owner_id = $1 AND name ILIKE '%anulado%' LIMIT 1", [ownerId]); const idAnulado = statusQ.rowCount > 0 ? statusQ.rows[0].id : null; - if (idAnulado) { + // 🛑 PARCHE: Desactivamos el escudo anti-viajes para Multiasistencia hasta que mapeemos bien sus 200 estados raros. + if (idAnulado && provider !== 'multiasistencia') { for (const svc of missingServices) { // Si el expediente estaba asignado a un técnico... if (svc.assigned_to) {