Actualizar server.js

This commit is contained in:
2026-02-15 18:01:14 +00:00
parent 516ba18a64
commit ce573ff86b

View File

@@ -73,6 +73,7 @@ async function autoUpdateDB() {
subscription_status TEXT DEFAULT 'active', subscription_status TEXT DEFAULT 'active',
paid_providers_count INT DEFAULT 0, paid_providers_count INT DEFAULT 0,
zones JSONB DEFAULT '[]', zones JSONB DEFAULT '[]',
status TEXT DEFAULT 'active',
created_at TIMESTAMP DEFAULT NOW() created_at TIMESTAMP DEFAULT NOW()
); );
CREATE TABLE IF NOT EXISTS login_codes ( CREATE TABLE IF NOT EXISTS login_codes (
@@ -394,7 +395,7 @@ app.post("/providers/import/:id", authMiddleware, async (req, res) => {
const phone = cleanData.phone || cleanData.phone2 || ""; const phone = cleanData.phone || cleanData.phone2 || "";
const name = cleanData.clientName || "Cliente Importado"; const name = cleanData.clientName || "Cliente Importado";
const address = cleanData.address || ""; const address = cleanData.address || "";
const cpExpediente = cleanData.cp || ""; // Extraemos Código Postal const cpExpediente = cleanData.cp || "";
const phoneClean = normalizePhone(phone); const phoneClean = normalizePhone(phone);
let clientId = null; let clientId = null;
@@ -410,7 +411,7 @@ app.post("/providers/import/:id", authMiddleware, async (req, res) => {
clientId = newC.rows[0].id; clientId = newC.rows[0].id;
} }
// --- 🚀 LÓGICA DE ASIGNACIÓN AUTOMÁTICA POR CP --- // --- 🚀 LÓGICA DE ASIGNACIÓN AUTOMÁTICA ---
let autoAssignedTo = null; let autoAssignedTo = null;
if (cpExpediente) { if (cpExpediente) {
// Buscamos un operario que esté ACTIVO y que tenga este CP en sus zones // Buscamos un operario que esté ACTIVO y que tenga este CP en sus zones
@@ -450,7 +451,7 @@ app.post("/providers/import/:id", authMiddleware, async (req, res) => {
provider, provider,
JSON.stringify(cleanData), JSON.stringify(cleanData),
cleanData.fecha_cita || 'NOW()', cleanData.fecha_cita || 'NOW()',
autoAssignedTo // Aquí pasamos el ID del operario si se encontró match autoAssignedTo // Se asigna automáticamente si hubo coincidencia
]); ]);
// 6. Marcar como importado // 6. Marcar como importado