fix(afluencia): validación duplicados + campos nombre + fix lada
- Lead creation: validación por email y teléfono normalizados (últimos 10 dígitos) - Si ya existe lead con mismo email/teléfono → 409 con aviso - Alta Afluencia: nombre dividido en Nombre(s), Apellido Paterno, Apellido Materno - Fix lada: strip robusto de +52 y +1 con/sin espacio - Backend + frontend actualizados
This commit is contained in:
@@ -212,6 +212,18 @@ export async function crearLead(
|
||||
const existente = await monday.buscarLeadPorTelefono(datos.telefono)
|
||||
if (existente) return { duplicado: { id: existente.id, nombre: existente.nombre } }
|
||||
}
|
||||
// Dedup por email en ambos tableros
|
||||
if (datos.email !== undefined && datos.email.trim() !== '') {
|
||||
const [leads, oportunidades] = await Promise.all([
|
||||
monday.getLeads(),
|
||||
monday.getOportunidades(),
|
||||
])
|
||||
const emailLower = datos.email.trim().toLowerCase()
|
||||
const existenteLead = leads.find((l) => l.email?.toLowerCase() === emailLower)
|
||||
if (existenteLead) return { duplicado: { id: existenteLead.id, nombre: existenteLead.nombre } }
|
||||
const existenteOp = oportunidades.find((o) => o.email?.toLowerCase() === emailLower)
|
||||
if (existenteOp) return { duplicado: { id: existenteOp.id, nombre: existenteOp.nombre } }
|
||||
}
|
||||
|
||||
if (datos.origen !== undefined) {
|
||||
const labels = await monday.labelsDeColumna(boardLeads, 'Origen')
|
||||
|
||||
@@ -139,11 +139,22 @@ export class CrmLocalService {
|
||||
* sincronizarse.
|
||||
*/
|
||||
async crearLead(datos: DatosLeadLocal, usuarioId?: string): Promise<ResultadoCapturaLocal> {
|
||||
if (datos.telefono !== undefined) {
|
||||
const existente = await prisma.leadCaptura.findFirst({
|
||||
where: { telefono: datos.telefono, board: 'LEADS' },
|
||||
// Dedup por teléfono (normalizando: últimos 10 dígitos)
|
||||
if (datos.telefono !== undefined && datos.telefono.trim() !== '') {
|
||||
const telLimpio = datos.telefono.replace(/\s+/g, '').slice(-10)
|
||||
if (telLimpio.length >= 7) {
|
||||
const existente = await prisma.leadCaptura.findFirst({
|
||||
where: { board: 'LEADS', telefono: { contains: telLimpio } },
|
||||
})
|
||||
if (existente) return { duplicado: { id: existente.leadId, nombre: existente.nombreLead } }
|
||||
}
|
||||
}
|
||||
// Dedup por email
|
||||
if (datos.email !== undefined && datos.email.trim() !== '') {
|
||||
const existenteEmail = await prisma.leadCaptura.findFirst({
|
||||
where: { email: datos.email.trim(), board: 'LEADS' },
|
||||
})
|
||||
if (existente) return { duplicado: { id: existente.leadId, nombre: existente.nombreLead } }
|
||||
if (existenteEmail) return { duplicado: { id: existenteEmail.leadId, nombre: existenteEmail.nombreLead } }
|
||||
}
|
||||
const id = idLocal()
|
||||
const datosMonday = {
|
||||
|
||||
Reference in New Issue
Block a user