Arregla CP alta manual

This commit is contained in:
2026-08-19 21:22:49 +00:00
parent 9f3e1d96c4
commit 3bb0c84e8e

View File

@@ -3969,13 +3969,20 @@ app.post("/services/manual-high", authMiddleware, async (req, res) => {
} }
// 2. Crear el Expediente // 2. Crear el Expediente
// 🩹 FIX: extraemos el Código Postal de la dirección en texto libre. Antes este campo
// nunca se guardaba en las altas manuales, así que la asignación automática (que exige
// que el CP coincida exactamente con una zona del operario) siempre fallaba al usar "00000".
const cpMatchAlta = (address || "").match(/\b\d{5}\b/);
const cpDetectado = cpMatchAlta ? cpMatchAlta[0] : "00000";
const rawData = { const rawData = {
"Nombre Cliente": name, "Nombre Cliente": name,
"Teléfono": phone, "Teléfono": phone,
"Dirección": address, "Dirección": address,
"Código Postal": cpDetectado,
"Descripción": description, "Descripción": description,
"guild_id": guild_id, "guild_id": guild_id,
"scheduled_date": "", "scheduled_date": "",
"scheduled_time": "", "scheduled_time": "",
"duration_minutes": duration_minutes || 60, "duration_minutes": duration_minutes || 60,
"Compañía": is_company ? company_name : "Particular" "Compañía": is_company ? company_name : "Particular"
@@ -4003,7 +4010,7 @@ app.post("/services/manual-high", authMiddleware, async (req, res) => {
fetch(`http://127.0.0.1:${port}/providers/automate/${newId}`, { fetch(`http://127.0.0.1:${port}/providers/automate/${newId}`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': req.headers.authorization }, headers: { 'Content-Type': 'application/json', 'Authorization': req.headers.authorization },
body: JSON.stringify({ guild_id, cp: "00000" }) body: JSON.stringify({ guild_id, cp: cpDetectado })
}).catch(e => console.error("Error lanzando bolsa:", e)); }).catch(e => console.error("Error lanzando bolsa:", e));
} }