Actualizar server.js
This commit is contained in:
26
server.js
26
server.js
@@ -1856,7 +1856,7 @@ async function dispatchToBolsa(serviceId, guildId, cp, accountId, userId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 📥 RECEPCIÓN DE SERVICIOS (DETECTOR MODO DIOS + AUTO-BOLSA)
|
// 📥 RECEPCIÓN DE SERVICIOS (DETECTOR + AUTO-BOLSA CORREGIDO)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -1871,7 +1871,7 @@ app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
|||||||
[req.user.accountId, provider]
|
[req.user.accountId, provider]
|
||||||
);
|
);
|
||||||
|
|
||||||
// CORRECCIÓN INTERRUPTOR (Acepta el '1' de la base de datos)
|
// ✅ CORRECCIÓN: Aceptamos 1, '1', 't' o true como "Encendido"
|
||||||
let autoDispatchEnabled = false;
|
let autoDispatchEnabled = false;
|
||||||
if (credsQ.rowCount > 0) {
|
if (credsQ.rowCount > 0) {
|
||||||
const val = credsQ.rows[0].auto_dispatch;
|
const val = credsQ.rows[0].auto_dispatch;
|
||||||
@@ -1880,7 +1880,13 @@ app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
|||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (const svc of services) {
|
for (const svc of services) {
|
||||||
const ref = svc['service_ref'] || svc['SERVICIO'] || svc['Referencia'] || svc['Expediente'] || (svc.raw_data && (svc.raw_data['SERVICIO'] || svc.raw_data['Referencia']));
|
|
||||||
|
const ref = svc['service_ref']
|
||||||
|
|| svc['SERVICIO']
|
||||||
|
|| svc['Referencia']
|
||||||
|
|| svc['Expediente']
|
||||||
|
|| (svc.raw_data && (svc.raw_data['SERVICIO'] || svc.raw_data['Referencia']));
|
||||||
|
|
||||||
if (!ref) continue;
|
if (!ref) continue;
|
||||||
|
|
||||||
let esUrgente = false;
|
let esUrgente = false;
|
||||||
@@ -1905,14 +1911,20 @@ app.post("/providers/scraped", authMiddleware, async (req, res) => {
|
|||||||
const newSvcId = insertRes.rows[0].id;
|
const newSvcId = insertRes.rows[0].id;
|
||||||
const autoStatus = insertRes.rows[0].automation_status;
|
const autoStatus = insertRes.rows[0].automation_status;
|
||||||
|
|
||||||
// CHIVATO DE CONSOLA
|
// 🕵️ CHIVATO: Esto aparecerá en tu consola de Coolify
|
||||||
console.log(`[DEBUG-BOLSA] Ref: ${ref} | Urgente: ${esUrgente} | Gremio: ${guildId} | Auto_ON: ${autoDispatchEnabled} | Estado: ${autoStatus}`);
|
console.log(`[DEBUG-RECEPCION] Ref: ${ref} | Urgente: ${esUrgente} | Gremio: ${guildId} | Auto_ON: ${autoDispatchEnabled}`);
|
||||||
|
|
||||||
// LANZAMIENTO AUTOMÁTICO
|
// 🔥 LANZAMIENTO AUTOMÁTICO 🔥
|
||||||
|
// Si es urgente, tiene gremio, el botón está ON y el servicio no ha sido procesado aún...
|
||||||
if (esUrgente && guildId && autoDispatchEnabled && (autoStatus === 'manual' || autoStatus === 'pending')) {
|
if (esUrgente && guildId && autoDispatchEnabled && (autoStatus === 'manual' || autoStatus === 'pending')) {
|
||||||
|
console.log(`⚡ [AUTO-DISPATCH] ¡Hillmer detectada! Lanzando a la bolsa...`);
|
||||||
const cpMatch = todoElTexto.match(/\b\d{5}\b/);
|
const cpMatch = todoElTexto.match(/\b\d{5}\b/);
|
||||||
dispatchToBolsa(newSvcId, guildId, cpMatch ? cpMatch[0] : "00000", req.user.accountId, req.user.sub);
|
const cpFinal = cpMatch ? cpMatch[0] : "00000";
|
||||||
|
|
||||||
|
// Usamos await para asegurar que se ejecute la lógica de bolsa
|
||||||
|
await dispatchToBolsa(newSvcId, guildId, cpFinal, req.user.accountId, req.user.sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
res.json({ ok: true, inserted: count });
|
res.json({ ok: true, inserted: count });
|
||||||
|
|||||||
Reference in New Issue
Block a user