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:
@@ -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